"Fossies" - the Fresh Open Source Software Archive

Member "horizon-14.0.4/openstack_dashboard/test/integration_tests/pages/project/volumes/snapshotspage.py" (22 Oct 2019, 5429 Bytes) of package /linux/misc/openstack/horizon-14.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    2 #    not use this file except in compliance with the License. You may obtain
    3 #    a copy of the License at
    4 #
    5 #         http://www.apache.org/licenses/LICENSE-2.0
    6 #
    7 #    Unless required by applicable law or agreed to in writing, software
    8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   10 #    License for the specific language governing permissions and limitations
   11 #    under the License.
   12 
   13 from selenium.webdriver.common import by
   14 
   15 from openstack_dashboard.test.integration_tests.pages import basepage
   16 from openstack_dashboard.test.integration_tests.pages.project.volumes.\
   17     volumespage import VolumesPage
   18 from openstack_dashboard.test.integration_tests.regions import forms
   19 from openstack_dashboard.test.integration_tests.regions import tables
   20 
   21 
   22 class VolumesnapshotsTable(tables.TableRegion):
   23     name = 'volume_snapshots'
   24     marker_name = 'snapshot_marker'
   25     prev_marker_name = 'prev_snapshot_marker'
   26 
   27     EDIT_SNAPSHOT_FORM_FIELDS = ("name", "description")
   28 
   29     CREATE_VOLUME_FORM_FIELDS = (
   30         "name", "description", "snapshot_source", "size")
   31 
   32     @tables.bind_table_action('delete')
   33     def delete_volume_snapshots(self, delete_button):
   34         """Batch Delete table action."""
   35         delete_button.click()
   36         return forms.BaseFormRegion(self.driver, self.conf)
   37 
   38     @tables.bind_row_action('delete')
   39     def delete_volume_snapshot(self, delete_button, row):
   40         """Per-entity delete row action."""
   41         delete_button.click()
   42         return forms.BaseFormRegion(self.driver, self.conf)
   43 
   44     @tables.bind_row_action('edit')
   45     def edit_snapshot(self, edit_button, row):
   46         edit_button.click()
   47         return forms.FormRegion(self.driver, self.conf,
   48                                 field_mappings=self.EDIT_SNAPSHOT_FORM_FIELDS)
   49 
   50     @tables.bind_row_action('create_from_snapshot')
   51     def create_volume(self, create_volume_button, row):
   52         create_volume_button.click()
   53         return forms.FormRegion(self.driver, self.conf,
   54                                 field_mappings=self.CREATE_VOLUME_FORM_FIELDS)
   55 
   56 
   57 class SnapshotsPage(basepage.BaseNavigationPage):
   58     SNAPSHOT_TABLE_NAME_COLUMN = 'Name'
   59     SNAPSHOT_TABLE_STATUS_COLUMN = 'Status'
   60     SNAPSHOT_TABLE_VOLUME_NAME_COLUMN = 'Volume Name'
   61     _volumes_tab_locator = (
   62         by.By.CSS_SELECTOR,
   63         'a[href*="tab=volumes_and_snapshots__volumes_tab"]')
   64 
   65     def __init__(self, driver, conf):
   66         super(SnapshotsPage, self).__init__(driver, conf)
   67         self._page_title = "Volume Snapshots"
   68 
   69     @property
   70     def volumesnapshots_table(self):
   71         return VolumesnapshotsTable(self.driver, self.conf)
   72 
   73     def switch_to_volumes_tab(self):
   74         self._get_element(*self._volumes_tab_locator).click()
   75         return VolumesPage(self.driver, self.conf)
   76 
   77     def _get_row_with_volume_snapshot_name(self, name):
   78         return self.volumesnapshots_table.get_row(
   79             self.SNAPSHOT_TABLE_NAME_COLUMN,
   80             name)
   81 
   82     def is_snapshot_present(self, name):
   83         return bool(self._get_row_with_volume_snapshot_name(name))
   84 
   85     def delete_volume_snapshot(self, name):
   86         row = self._get_row_with_volume_snapshot_name(name)
   87         confirm_form = self.volumesnapshots_table.delete_volume_snapshot(row)
   88         confirm_form.submit()
   89 
   90     def delete_volume_snapshots(self, names):
   91         for name in names:
   92             row = self._get_row_with_volume_snapshot_name(name)
   93             row.mark()
   94         confirm_form = self.volumesnapshots_table.delete_volume_snapshots()
   95         confirm_form.submit()
   96 
   97     def is_volume_snapshot_deleted(self, name):
   98         return self.volumesnapshots_table.is_row_deleted(
   99             lambda: self._get_row_with_volume_snapshot_name(name))
  100 
  101     def is_volume_snapshot_available(self, name):
  102         def cell_getter():
  103             row = self._get_row_with_volume_snapshot_name(name)
  104             return row and row.cells[self.SNAPSHOT_TABLE_STATUS_COLUMN]
  105 
  106         return bool(self.volumesnapshots_table.wait_cell_status(cell_getter,
  107                                                                 'Available'))
  108 
  109     def get_volume_name(self, snapshot_name):
  110         row = self._get_row_with_volume_snapshot_name(snapshot_name)
  111         return row.cells[self.SNAPSHOT_TABLE_VOLUME_NAME_COLUMN].text
  112 
  113     def edit_snapshot(self, name, new_name=None, description=None):
  114         row = self._get_row_with_volume_snapshot_name(name)
  115         snapshot_edit_form = self.volumesnapshots_table.edit_snapshot(row)
  116         if new_name:
  117             snapshot_edit_form.name.text = new_name
  118         if description:
  119             snapshot_edit_form.description.text = description
  120         snapshot_edit_form.submit()
  121 
  122     def create_volume_from_snapshot(self, snapshot_name, volume_name=None,
  123                                     description=None, volume_size=None):
  124         row = self._get_row_with_volume_snapshot_name(snapshot_name)
  125         volume_form = self.volumesnapshots_table.create_volume(row)
  126         if volume_name:
  127             volume_form.name.text = volume_name
  128         if description:
  129             volume_form.description.text = description
  130         if volume_size is None:
  131             volume_size = self.conf.volume.volume_size
  132         volume_form.size.value = volume_size
  133         volume_form.submit()