summaryrefslogtreecommitdiff
path: root/openstack_dashboard/test/integration_tests/pages/project/orchestration/stackspage.py
blob: 3b83d036446a5aa080d9a5da5bf787ea748b912a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from openstack_dashboard.test.integration_tests import config
from openstack_dashboard.test.integration_tests.pages import basepage
from openstack_dashboard.test.integration_tests.regions import forms
from openstack_dashboard.test.integration_tests.regions import tables


class StacksTable(tables.TableRegion):
    name = "stacks"
    SELECT_TEMPLATE_FORM_FIELDS = ("template_source", "template_upload",
                                   "template_data", "template_url",
                                   "environment_source", "environment_upload",
                                   "environment_data")
    LAUNCH_STACK_FORM_FIELDS = ("stack_name", "timeout_mins",
                                "enable_rollback", "password")

    @tables.bind_table_action('launch')
    def select_template(self, launch_button):
        launch_button.click()
        return forms.FormRegion(
            self.driver, self.conf,
            field_mappings=self.SELECT_TEMPLATE_FORM_FIELDS)

    def launch_stack(self):
        return forms.FormRegion(self.driver, self.conf,
                                field_mappings=self.LAUNCH_STACK_FORM_FIELDS)

    @tables.bind_table_action('delete')
    def delete_stack(self, delete_button):
        delete_button.click()
        return forms.BaseFormRegion(self.driver, self.conf)


class StacksPage(basepage.BaseNavigationPage):
    DEFAULT_TEMPLATE_SOURCE = 'raw'

    CONFIG = config.get_config()
    DEFAULT_PASSWORD = CONFIG.identity.admin_password
    STACKS_TABLE_NAME_COLUMN = 'name'
    STACKS_TABLE_STATUS_COLUMN = 'stack_status'

    def __init__(self, driver, conf):
        super(StacksPage, self).__init__(driver, conf)
        self._page_title = "Stacks"

    @property
    def stacks_table(self):
        return StacksTable(self.driver, self.conf)

    def _get_row_with_stack_name(self, name):
        return self.stacks_table.get_row(self.STACKS_TABLE_NAME_COLUMN, name)

    def create_stack(self, stack_name, template_data,
                     template_source=DEFAULT_TEMPLATE_SOURCE,
                     environment_source=None,
                     environment_upload=None,
                     timeout_mins=None,
                     enable_rollback=None,
                     password=DEFAULT_PASSWORD):
        select_template_form = self.stacks_table.select_template()
        select_template_form.template_source.value = template_source
        select_template_form.template_data.text = template_data
        select_template_form.submit()
        launch_stack_form = self.stacks_table.launch_stack()
        launch_stack_form.stack_name.text = stack_name
        launch_stack_form.password.text = password
        launch_stack_form.submit()

    def delete_stack(self, name):
        row = self._get_row_with_stack_name(name)
        row.mark()
        confirm_delete_stacks_form = self.stacks_table.delete_stack()
        confirm_delete_stacks_form.submit()

    def is_stack_present(self, name):
        return bool(self._get_row_with_stack_name(name))

    def is_stack_create_complete(self, name):
        def cell_getter():
            row = self._get_row_with_stack_name(name)
            return row and row.cells[self.STACKS_TABLE_STATUS_COLUMN]

        return bool(self.stacks_table.wait_cell_status(cell_getter,
                                                       'Create Complete'))

    def is_stack_deleted(self, name):
        return self.stacks_table.is_row_deleted(
            lambda: self._get_row_with_stack_name(name))