Esempio n. 1
0
class SelinuxPage(PageObject):
    # frame name
    frame_right_name = "cockpit1:localhost/selinux/setroubleshoot"

    policy_btn_div = PageElement(css=".btn-group")
    policy_btn = PageElement(css="label.btn:nth-child(2) > span:nth-child(2)")

    def __init__(self, *args, **kwargs):
        super(SelinuxPage, self).__init__(*args, **kwargs)
        self.get("/selinux/setroubleshoot")
        self.wait(5)

    def basic_check_elements_exists(self):
        with self.switch_to_frame(self.frame_right_name):
            assert self.policy_btn_div, "No Selinux policy btn exists"
Esempio n. 2
0
class DiagnosticPage(PageObject):
    create_report_btn = PageElement(class_name="btn-primary")

    # Elements after click the create_report_btn
    sos_cancel_btn = PageElement(id_="sos-cancel")
    download_done_div = PageElement(
        xpath=".//*[@id='sos-download']/center/div")
    download_sos_btn = PageElement(
        xpath=".//*[@id='sos-download']/center/button")

    # frame name
    frame_right_name = "cockpit1:localhost/sosreport"

    def __init__(self, *args, **kwargs):
        super(DiagnosticPage, self).__init__(*args, **kwargs)
        self.get("/sosreport")
        self.wait(5)

    def basic_check_elements_exists(self):
        with self.switch_to_frame(self.frame_right_name):
            assert self.create_report_btn, "No create report btn exists"

    def create_sos_report(self):
        """
        Purpose:
            Create the diagnostic report
        """
        with self.switch_to_frame(self.frame_right_name):
            self.create_report_btn.click()

    def check_sosreport_can_be_downloaded(self):
        """
        Purpose:
            Check the sosreport can be downloaded
        """
        with self.switch_to_frame(self.frame_right_name):
            assert self.download_done_div, "sosreport is not created successfully"
            assert re.search("Done", self.download_done_div.text),   \
                "sosreport is not created successfully"
            assert self.download_sos_btn, "sosreport can not be downloaded"
            assert re.search("Download", self.download_sos_btn.text),    \
                "sosreport can not be downloaded"
class DiagnosticPage(PageObject):
    # frame name
    frame_right_name = "cockpit1:localhost/sosreport"

    create_report_btn = PageElement(css="button.btn:nth-child(4)")

    # Elements after click the create_report_btn
    sos_cancel_btn = PageElement(id_="sos-cancel")
    download_done_div = PageElement(
        xpath=".//*[@id='sos-download']/center/div")
    download_sos_btn = PageElement(
        xpath=".//*[@id='sos-download']/center/button")

    def __init__(self, *args, **kwargs):
        super(DiagnosticPage, self).__init__(*args, **kwargs)
        self.get("/sosreport")
        self.wait(5)

    def basic_check_elements_exists(self):
        with self.switch_to_frame(self.frame_right_name):
            assert self.create_report_btn, "No create report btn exists"
Esempio n. 4
0
class DashboardPage(PageObject):
    """ To check Ovirt dashboard on Virtualization panel."""
    add_btn = PageElement(id_="dashboard-add")
    enable_btn = PageElement(id_="dashboard-enable-edit")
    cpu_link = PageElement(link_text="CPU")
    memory_link = PageElement(link_text="Memory")
    network_link = PageElement(link_text="Network")
    disk_link = PageElement(link_text="Disk I/O")

    # frame name
    frame_right_name = "cockpit1:localhost/dashboard"

    def __init__(self, *args, **kwargs):
        super(DashboardPage, self).__init__(*args, **kwargs)
        self.get("/dashboard")
        self.wait(period=5)

    def basic_check_elements_exists(self):
        with self.switch_to_frame(self.frame_right_name):
            assert self.cpu_link, "CPU button not exist"
            assert self.memory_link, "Memory button not exist"
            assert self.network_link, "Network button not exist"
            assert self.disk_link, "Disk button not exist"
            assert self.add_btn, "Add button not exist"
            assert self.enable_btn, "Edit button not exist"
            self.wait()
Esempio n. 5
0
class KdumpPage(PageObject):
    # frame name
    frame_right_name = "cockpit1:localhost/kdump"

    kdump_status_btn = PageElement(
        css="label.btn:nth-child(1) > span:nth-child(2)")
    service_link = PageElement(
        xpath="//*[@id='app']/div/table/tr[1]/td[2]/div/a/span")
    dump_location_link = PageElement(
        xpath="//*[@id='app']/div/table/tr[3]/td[2]/a")
    test_config_btn = PageElement(css="button.btn")

    # Elements after click dump_location_link
    location_select = PageElement(css=".dropdown-toggle")
    directory_input = PageElement(id_="kdump-settings-local-directory")
    compression_checkbox = PageElement(id_="kdump-settings-compression")
    cancel_btn = PageElement(css=".cancel")
    apply_btn = PageElement(css="button.btn:nth-child(2)")

    # Elements after click test_config_btn
    crash_system_btn = PageElement(css="button.btn:nth-child(2)")

    def __init__(self, *args, **kwargs):
        super(KdumpPage, self).__init__(*args, **kwargs)
        self.get("/kdump")
        self.wait(5)

    def basic_check_elements_exists(self):
        with self.switch_to_frame(self.frame_right_name):
            assert self.kdump_status_btn, "Kdump status button not exists"
            assert self.service_link.text == "Service is running", \
                "Kdump service is not running, as '{}'".format(self.service_link.text)
            assert self.dump_location_link.text == "locally in /var/crash", \
                "Dump location is not default to {}, not /var/crash".format(
                    self.dump_location_link.text)
            assert self.test_config_btn, "Test configuration button not exists"
Esempio n. 6
0
class LoginPage(PageObject):
    """Login page action method come here"""

    brand_log = PageElement(id_="brand")

    username_input = PageElement(id_="login-user-input")
    password_input = PageElement(id_="login-password-input")
    login_btn = PageElement(id_="login-button")
    login_error_message = PageElement(id_="login-error-message")

    # Other options
    other_option = PageElement(id_="option-caret")
    server_input = PageElement(id_="server-field")

    # After click the Login button
    md5_input = PageElement(id_="conversation-input")

    def __init__(self, *args, **kwargs):
        super(LoginPage, self).__init__(*args, **kwargs)
        self.get("/")
        self.wait_until_element_visible(self.username_input)

    def basic_check_elements_exists(self):
        assert self.username_input, "input username not exist"
        assert self.password_input, "input password not exist"
        assert self.login_btn, "login btn not exist"
        self.wait()

    def login_with_credential(self, username, password):
        self.username_input.clear()
        self.wait(0.5)
        self.username_input.send_keys(username)
        self.wait(0.5)

        self.password_input.clear()
        self.wait(0.5)
        self.password_input.send_keys(password)
        self.wait(0.5)

        self.login_btn.click()
        self.wait(2)
        assert not self.username_input, "Login to cockpit failed"
class KdumpServicePage(PageObject):
    # frame name
    frame_right_name = "cockpit1:localhost/system/services"

    service_status_select = PageElement(
        css="#service-unit-action > button:nth-child(2)")
    # Button after click the service_status_select
    start_btn = PageElement(
        css=
        "#service-unit-action > ul:nth-child(3) > li:nth-child(1) > a:nth-child(1)"
    )
    stop_btn = PageElement(
        css=
        "#service-unit-action > ul:nth-child(3) > li:nth-child(2) > a:nth-child(1)"
    )
    restart_btn = PageElement(
        css=
        "#service-unit-action > ul:nth-child(3) > li:nth-child(3) > a:nth-child(1)"
    )
    reload_btn = PageElement(
        css=
        "#service-unit-action > ul:nth-child(3) > li:nth-child(4) > a:nth-child(1)"
    )

    enable_disable_select = PageElement(
        css="#service-file-action > button:nth-child(2)")
    # Button after click the enable_disable_select
    enable_btn = PageElement(
        css=
        "#service-file-action > ul:nth-child(3) > li:nth-child(1) > a:nth-child(1)"
    )
    disable_btn = PageElement(
        css=
        "#service-file-action > ul:nth-child(3) > li:nth-child(3) > a:nth-child(1)"
    )

    def __init__(self, *args, **kwargs):
        super(KdumpServicePage, self).__init__(*args, **kwargs)
        self.get("/system/services#/kdump.service")
        self.wait(5)
Esempio n. 8
0
class DashboardUiPage(PageObject):
    """To check Node status and System info on Virtualization panel."""
    # frame name
    frame_right_name = "cockpit1:localhost/ovirt-dashboard"

    virtualization_title = PageElement(tag_name='h2')

    node_status_title = PageElement(
        xpath='//*[@id="content"]/div/div/div[1]/table/tbody[1]/tr/td/h4')

    vm_title = PageElement(
        xpath='//*[@id="content"]/div/div/div[2]/div/ul/li/div/div[2]')
    vm_quantity = PageElement(
        xpath='//*[@id="content"]/div/div/div[2]/div/ul/li/div/div[3]/strong')

    health_title = PageElement(
        xpath='//*[@id="content"]/div/div/div[1]/table/tbody[2]/tr[1]/td[1]')
    health_link = PageElement(
        xpath=
        './/*[@id="content"]/div/div/div[1]/table/tbody[2]/tr[1]/td[2]/div[1]/a/div'
    )
    ok_icons = MultiPageElement(class_name="pficon-ok")

    cur_layer_title = PageElement(
        xpath='//*[@id="content"]/div/div/div[1]/table/tbody[2]/tr[2]/td[1]')
    cur_layer_link = PageElement(
        xpath=
        './/*[@id="content"]/div/div/div[1]/table/tbody[2]/tr[2]/td[2]/div[1]/a'
    )

    rollback_btn = PageElement(
        xpath=
        '/html/body/div/div/div[2]/div/div/div[1]/table/tbody[2]/tr[2]/td[2]/div[1]/span/button'
    )

    system_title = PageElement(
        xpath='//*[@id="content"]/div/div/div[1]/table/tbody[3]/tr/td/h4')

    network_info_title = PageElement(
        xpath='//*[@id="content"]/div/div/div[1]/table/tbody[4]/tr[1]/td[1]')
    network_info_link = PageElement(
        xpath='//*[@id="content"]/div/div/div[1]/table/tbody[4]/tr[1]/td[2]/a')
    system_logs_title = PageElement(
        xpath='//*[@id="content"]/div/div/div[1]/table/tbody[4]/tr[2]/td[1]')
    system_logs_link = PageElement(
        xpath='//*[@id="content"]/div/div/div[1]/table/tbody[4]/tr[2]/td[2]/a')
    storage_title = PageElement(
        xpath='//*[@id="content"]/div/div/div[1]/table/tbody[4]/tr[3]/td[1]')
    storage_link = PageElement(
        xpath='//*[@id="content"]/div/div/div[1]/table/tbody[4]/tr[3]/td[2]/a')
    ssh_key_title = PageElement(
        xpath='//*[@id="content"]/div/div/div[1]/table/tbody[5]/tr/td[1]')
    ssh_key_link = PageElement(
        xpath='//*[@id="content"]/div/div/div[1]/table/tbody[5]/tr/td[2]/a')

    # After click health link
    node_health_dialog_title = PageElement(
        xpath=
        '//*[@id="content"]/div/div/div[1]/table/tbody[2]/tr[1]/td[2]/div[2]/div/div/div/div[1]/h4'
    )
    # accordion_header_btn: like "Thin storage","basic storage","Mount points" button
    health_dialog_btns = MultiPageElement(class_name="accordion-header")
    # close_btn : close button,like "X"
    close_btns = MultiPageElement(class_name="close")

    # After click current layer link
    # elements under Node information dialog
    cur_layer_dialog_title = PageElement(
        xpath=
        '//*[@id="content"]/div/div/div[1]/table/tbody[2]/tr[2]/td[2]/div[2]/div/div/div/div[1]/h4'
    )
    layer_dialog_btns = MultiPageElement(class_name='accordion-header')
    entry_txts = MultiPageElement(class_name="col-md-6")

    # Host RSA key title
    ssh_key_dialog_title = PageElement(
        xpath=
        '//*[@id="content"]/div/div/div[1]/table/tbody[5]/tr/td[2]/div/div/div/div/div[1]/h4'
    )

    def __init__(self, *args, **kwargs):
        super(DashboardUiPage, self).__init__(*args, **kwargs)
        self.get("/ovirt-dashboard")
        self.wait(5)

    def basic_check_elements_exists(self):
        with self.switch_to_frame(self.frame_right_name):
            # virtualization title
            assert self.virtualization_title.text == 'Virtualization', \
                "Virtualization Title not correct"
            # node status title
            assert self.node_status_title.text == "Node Status", \
                "Node Status not correct"
            # vm title and quantity
            assert self.vm_title.text == "Virtual Machines", \
                "Virtual Machines title not correct"
            assert self.vm_quantity, "Vm quantity not exists"
            # health title and status
            assert self.health_title.text == 'Health', \
                "Health title not correct"
            assert re.search('ok', self.health_link.text), "Health is not ok"
            # current layer title and info
            assert self.cur_layer_title.text == "Current Layer", \
                "Current Layer title not correct"
            assert self.cur_layer_link, "Current layer button not exists"
            # rollback button
            assert self.rollback_btn, "Rollback button not exists"
            # system title and info
            assert self.system_title.text == "System", \
                "System title not correct"
            # network info title and link
            assert re.search('Networking Information', self.network_info_title.text), \
                "Network information title not correct"
            assert self.network_info_link, "Network info link not exists"
            # system logs title and link
            assert re.search("System Logs", self.system_logs_title.text), \
                "System logs title not correct"
            assert self.system_logs_link, "System logs link not exists"
            # storage title and link
            assert re.search("Storage", self.storage_title.text), \
                "Storage title not correct"
            assert self.storage_link, "Storage link not exists"
            # ssh key title and link
            assert re.search("SSH Host Key", self.ssh_key_title.text), \
                "SSH host key title not correct"
            assert self.ssh_key_link, "SSH host key link not exists"
class LogPage(PageObject):
    current_day_menu = PageElement(
        xpath=".//*[@id='journal-current-day-menu']/button")
    errors_btn = PageElement(xpath=".//*[@id='journal-prio']/button[1]")
    warnnings_btn = PageElement(xpath=".//*[@id='journal-prio']/button[2]")
    notices_btn = PageElement(xpath=".//*[@id='journal-prio']/button[3]")
    all_btn = PageElement(xpath=".//*[@id='journal-prio']/button[4]")

    # Elements after click the current-day-menu
    recent_btn = PageElement(
        xpath=".//*[@id='journal-current-day-menu']/ul/li[1]/a")
    current_boot_btn = PageElement(
        xpath=".//*[@id='journal-current-day-menu']/ul/li[2]/a")
    last_24hours_btn = PageElement(
        xpath=".//*[@id='journal-current-day-menu']/ul/li[3]/a")
    last_7days_btn = PageElement(
        xpath=".//*[@id='journal-current-day-menu']/ul/li[4]/a")

    # frame name
    frame_right_name = "cockpit1:localhost/system/logs"

    def __init__(self, *args, **kwargs):
        super(LogPage, self).__init__(*args, **kwargs)
        self.get("/system/logs")
        self.wait(5)

    def basic_check_elements_exists(self):
        with self.switch_to_frame(self.frame_right_name):
            assert self.current_day_menu, "current day menu button not exists"
            assert self.errors_btn, "errors button not exists"
            assert self.warnnings_btn, "warnning button not exists"
            assert self.notices_btn, "notices button not exists"
            assert self.all_btn, "all button not exists"

    def check_recent_logs(self):
        """
        Purpose:
            Check recent logs including errors, warnnings, notices, all
        """
        with self.switch_to_frame(self.frame_right_name):
            self.errors_btn.click()
            self.save_screenshot("recent_error_logs.png")
            self.wait(3)

            self.warnnings_btn.click()
            self.save_screenshot("recent_warnnings_logs.png")
            self.wait(3)

            self.notices_btn.click()
            self.save_screenshot("recent_notices_logs.png")
            self.wait(3)

            self.all_btn.click()
            self.save_screenshot("recent_all_logs.png")
            self.wait(3)

    def check_current_boot_logs(self):
        """
        Purpose:
            Check current boot logs including errors, warnnings, notices, all
        """
        with self.switch_to_frame(self.frame_right_name):
            self.current_day_menu.click()
            self.wait(3)
            self.current_boot_btn.click()
            self.wait(5)
            self.errors_btn.click()
            self.wait(3)
            self.save_screenshot("current_boot_error_logs.png")

            self.warnnings_btn.click()
            self.wait(3)
            self.save_screenshot("current_boot_warnnings_logs.png")

            self.notices_btn.click()
            self.wait(3)
            self.save_screenshot("current_boot_notices_logs.png")

            self.all_btn.click()
            self.wait(3)
            self.save_screenshot("current_boot_all_logs.png")

    def check_last_24hours_logs(self):
        """
        Purpose:
            Check current boot logs including errors, warnnings, notices, all
        """
        with self.switch_to_frame(self.frame_right_name):
            self.current_day_menu.click()
            self.wait(3)
            self.last_24hours_btn.click()
            self.wait(5)

            self.errors_btn.click()
            self.wait(3)
            self.save_screenshot("last_24_hours_error_logs.png")

            self.warnnings_btn.click()
            self.wait(3)
            self.save_screenshot("last_24_hours_warnnings_logs.png")

            self.notices_btn.click()
            self.wait(3)
            self.save_screenshot("last_24_hours_notices_logs.png")

            self.all_btn.click()
            self.wait(3)
            self.save_screenshot("last_24_hours_all_logs.png")

    def check_last_7days_logs(self):
        """
        Purpose:
            Check current boot logs including errors, warnnings, notices, all
        """
        with self.switch_to_frame(self.frame_right_name):
            self.current_day_menu.click()
            self.wait(3)
            self.last_7days_btn.click()
            self.wait(5)

            self.errors_btn.click()
            self.wait(3)
            self.save_screenshot("last_7days_error_logs.png")

            self.warnnings_btn.click()
            self.wait(3)
            self.save_screenshot("last_7days_warnnings_logs.png")

            self.notices_btn.click()
            self.wait(3)
            self.save_screenshot("last_7days_notices_logs.png")

            self.all_btn.click()
            self.wait(3)
            self.save_screenshot("last_7days_all_logs.png")
Esempio n. 10
0
class AccountPage(PageObject):
    # frame name
    frame_right_name = "cockpit1:localhost/users"

    accounts_create_btn = PageElement(id_="accounts-create")
    cockpit_accounts_div = MultiPageElement(class_name="cockpit-account")

    # Elements after click the accounts create page
    real_name_input = PageElement(id_="accounts-create-real-name")
    user_name_input = PageElement(id_="accounts-create-user-name")
    password_input = PageElement(id_="accounts-create-pw1")
    confirm_input = PageElement(id_="accounts-create-pw2")
    access_checkbox = PageElement(id_="accounts-create-locked")
    create_btn = PageElement(id_="accounts-create-create")

    # Elements after click the cockpit-accounts-div
    account_username = PageElement(id_="account-user-name")
    account_delete = PageElement(id_="account-delete")

    # Elements after click the Delete button
    delete_files_checkbox = PageElement(id_="account-confirm-delete-files")
    delete_apply_btn = PageElement(id_="account-confirm-delete-apply")

    def __init__(self, *args, **kwargs):
        super(AccountPage, self).__init__(*args, **kwargs)
        self.get("/users")
        self.wait(5)

    def basic_check_elements_exists(self):
        with self.switch_to_frame(self.frame_right_name):
            assert self.accounts_create_btn, "account create button not exists"
            assert self.cockpit_accounts_div, "cockpit account div not exists"
class SubscriptionPage(PageObject):
    """Subscription-manager for host to register to RHSM/Satellite server"""
    # frame name
    frame_right_name = "cockpit1:localhost/subscriptions"

    subscription_title = PageElement(css="div.subscription-status-ct>h2")
    status_txt = PageElement(css="div.subscription-status-ct>label")

    # register button
    register_sys_btn = PageElement(css="div.subscription-status-ct>button")

    # Elements after click the register button
    register_dialog_title = PageElement(css="h4.modal-title")
    login_input = PageElement(id_="subscription-register-username")
    passwd_input = PageElement(id_="subscription-register-password")
    key_input = PageElement(id_="subscription-register-key")
    org_input = PageElement(id_="subscription-register-org")
    apply_cancel_btns = MultiPageElement(css="div.modal-footer>button")

    url_select_btn = PageElement(
        xpath=".//*[@id='subscription-register-url']/button")
    url_default_item = PageElement(
        xpath=".//*[@id='subscription-register-url']/ul/li[1]/a")
    url_custom_item = PageElement(
        xpath=".//*[@id='subscription-register-url']/ul/li[2]/a")
    url_input = PageElement(id_="subscription-register-url-custom")

    # Elements under "Installed products"
    installed_product_title = PageElement(css="caption.cockpit-caption")
    installed_product_btn = PageElement(tag_name="th")
    details_titles = MultiPageElement(css="td.form-tr-ct-title")
    details_contents = MultiPageElement(css="td.form-tr-ct-title+td>span")

    def __init__(self, *args, **kwargs):
        super(SubscriptionPage, self).__init__(*args, **kwargs)
        self.get("/subscriptions")
        self.wait(5)

    def basic_check_elements_exists(self,
                                    version,
                                    product_name="Red Hat Virtualization Host",
                                    product_id="328",
                                    arch="x86_64"):

        with self.switch_to_frame(self.frame_right_name):
            assert self.subscription_title.text == 'Subscriptions', \
                "subscription title not correct"
            assert self.status_txt.text == "Status: System isn't registered", \
                "Status not correct"
            assert self.register_sys_btn, "register system btn not exist"

            assert self.installed_product_title.text == "Installed products", \
                "installed product title not correct"
            assert self.installed_product_btn.text == product_name, \
                "installed product is {}".format(self.installed_product_btn.text)

            self.installed_product_btn.click()
            self.wait()

            product_name_title = list(self.details_titles)[0]
            product_id_title = list(self.details_titles)[1]
            version_title = list(self.details_titles)[2]
            arch_title = list(self.details_titles)[3]
            status_title = list(self.details_titles)[4]
            start_title = list(self.details_titles)[5]
            end_title = list(self.details_titles)[6]

            product_name_content = list(self.details_contents)[0]
            product_id_content = list(self.details_contents)[1]
            version_content = list(self.details_contents)[2]
            arch_content = list(self.details_contents)[3]
            status_content = list(self.details_contents)[4]
            start_content = list(self.details_contents)[5]
            end_content = list(self.details_contents)[6]

            assert product_name_title.text == "Product name", \
                "product name title not correct"
            assert product_name_content.text == product_name, \
                "product name is {}, not {}".format(
                    product_name_content.text, product_name)
            assert product_id_title.text == "Product ID", \
                "product id title not correct"
            assert product_id_content.text == product_id, \
                "product id is {}, not {}".format(self.product_id_content.text, product_id)
            assert version_title.text == "Version", "Version title not correct"
            assert re.search(version_content.text,
                             version), "Product verison not correct"
            assert arch_title.text == "Architecture", "Arch title not correct"
            assert arch_content.text == arch, "Arch is {}, not {}".format(
                arch_content.text, arch)
            assert status_title.text == "Status", "status title not correct"
            assert status_content.text == "Unknown", \
                "status content is {}, not unkonwn".format(
                    start_content.text)
            assert start_title.text == "Starts", "start title not correct"
            assert start_content.text == "", \
                "start content is {}, not none".format(start_content.text)
            assert end_title.text == "Ends", "end title not correct"
            assert end_content.text == "", \
                "end content is {}, not none".format(end_content.text)
Esempio n. 12
0
class DashboardPage(PageObject):
    """ To check Ovirt dashboard on Virtualization panel."""
    add_btn = PageElement(id_="dashboard-add")
    enable_btn = PageElement(id_="dashboard-enable-edit")
    cpu_link = PageElement(link_text="CPU")
    memory_link = PageElement(link_text="Memory")
    network_link = PageElement(link_text="Network")
    disk_link = PageElement(link_text="Disk I/O")

    # Elements after click the "add server" button
    add_address_input = PageElement(id_="add-machine-address")
    # add_btn = PageElement(class_name="btn_primary")
    cancel_btn = PageElement(class_name="btn-default")

    # Elements after click submit
    # connect_btn = PageElement(class_name="btn_primary")
    user_input = PageElement(id_="login-custom-user")
    password_input = PageElement(id_="login-custom-password")
    # login_btn = PageElement(class_name="btn-primary")

    # All buttons with class "btn-primary"
    primary_btns = MultiPageElement(class_name="btn-primary")

    # Elements under severs
    servers = MultiPageElement(class_name="host-label")

    # frame name
    frame_right_name = "cockpit1:localhost/dashboard"

    def __init__(self, *args, **kwargs):
        super(DashboardPage, self).__init__(*args, **kwargs)
        self.get("/dashboard")
        self.wait(5)

    def basic_check_elements_exists(self):
        with self.switch_to_frame(self.frame_right_name):
            assert self.cpu_link, "CPU button not exist"
            assert self.memory_link, "Memory button not exist"
            assert self.network_link, "Network button not exist"
            assert self.disk_link, "Disk button not exist"
            assert self.add_btn, "Add button not exist"
            assert self.enable_btn, "Edit button not exist"

    def check_cpu(self):
        """
        Purpose:
            Check cpu info by save screenshot of CPU link
        """
        with self.switch_to_frame(self.frame_right_name):
            self.cpu_link.click()
            self.wait(120)
            self.save_screenshot("cpu_graph.png")

    def check_memory(self):
        """
        Purpose:
            Check memory info by save screenshot of Memory link
        """
        with self.switch_to_frame(self.frame_right_name):
            self.memory_link.click()
            self.wait(120)
            self.save_screenshot("memory_graph.png")

    def check_network(self):
        """
        Purpose:
            Check network info by save screenshot of Network link
        """
        with self.switch_to_frame(self.frame_right_name):
            self.network_link.click()
            self.wait(120)
            self.save_screenshot("network_graph.png")

    def check_disk_io(self):
        """
        Purpose:
            Check Disk IO info by save screenshot of Network link
        """
        with self.switch_to_frame(self.frame_right_name):
            self.disk_link.click()
            self.wait(120)
            self.save_screenshot("disk_io_graph.png")

    def check_server_can_be_added(self, another_host, another_password):
        """
        Purpose:
            Check another server can be added to cockpit on dashboard page
        """
        with self.switch_to_frame(self.frame_right_name):
            self.add_btn.click()
            self.wait(2)

            self.add_address_input.send_keys(another_host)
            self.wait(2)

            # Find the submit btn by primary btns and click it
            for each_btn in list(self.primary_btns):
                if re.search('Add', each_btn.text):
                    submit_btn = each_btn
            submit_btn.click()
            self.wait(1)

            # Find the Connect btn by primary btn and click it
            connect_btn = None
            for each_btn in list(self.primary_btns):
                if re.search('Connect', each_btn.text):
                    connect_btn = each_btn
            if connect_btn:
                connect_btn.click()

            self.user_input.send_keys("root")
            self.password_input.send_keys(another_password)
            self.wait(1)

            # Find the login button from primary btn and click it
            for each_btn in list(self.primary_btns):
                if re.search('Log In', each_btn.text):
                    login_btn = each_btn
            login_btn.click()
            self.wait(5)

            assert len(list(self.servers)) == 2, "Failed to add another host"
Esempio n. 13
0
class HePage(PageObject):
    """
    Hosted engine page
    """
    # frame name
    frame_right_name = "cockpit1:localhost/ovirt-dashboard"

    deploy_icon = PageElement(class_name="btn-primary")
    mac_address = PageElement(
        xpath="//input[@title='Enter the MAC address for the VM.']")
    engine_hostname = PageElement(
        xpath="//input[@placeholder='Engine VM Host Name']")
    domain_name = PageElement(xpath="//input[@placeholder='Engine VM Domain']")
    passwd = MultiPageElement(xpath="//input[@type='password']")
    nfs_path = PageElement(xpath="//input[@placeholder='host:/path']")
    next_button = PageElement(
        xpath="//button[@class='btn btn-primary wizard-pf-next']")
    deploy_button = PageElement(
        xpath="//button[@class='btn btn-primary wizard-pf-finish']")
    checkboxes = MultiPageElement(xpath="//input[@type='checkbox']")
    default_button = MultiPageElement(
        xpath="//button[@class='btn btn-default']")

    alert_warning_maintenance = MultiPageElement(
        xpath="//div[@class='alert alert-warning']")

    ok_icons = MultiPageElement(class_name="pficon-ok")
    vcenters = MultiPageElement(class_name="vcenter")
    btns = MultiPageElement(class_name="btn-default")
    panel_titles = MultiPageElement(class_name="panel-title")
    panel_bodys = MultiPageElement(class_name="panel-body")

    vm_state_txts = MultiPageElement(
        xpath=".//*[@class='list-view-pf-additional-info']/div/div")
    list_group_item_txts = MultiPageElement(class_name="list-group-item-text")

    #global_maintenance_div = PageElement(xpath=".//*[@class='panel-body']/div")
    global_maintenance_div = PageElement(class_name="alert-warning")

    def __init__(self, *args, **kwargs):
        super(HePage, self).__init__(*args, **kwargs)
        self.get("/ovirt-dashboard#/he")
        self.wait(10)

    def check_three_buttons(self):
        """
        Purpose:
            Chech three "Maintenance" buttons exist
        """
        assert len(list(self.btns)) == 3, "Maintenance buttons not exist"

    def check_local_maintenance_hint(self):
        """
        Purpose:
            Check the local maintenance on one host hint
        """
        assert self.alert_warning_maintenance[0].text == 'Local maintenance cannot be enabled with a single host',   \
            "There is no hint about putting the HostedEngine into local maintenance on one host"

    def check_engine_status(self):
        """
        Purpose:
            Check the engine status
        """
        with self.switch_to_frame(self.frame_right_name):
            ok_icons = list(self.ok_icons)
            assert len(ok_icons) == 2, "Hosted engine status not up"

            he_status_txt = list(self.vcenters)[0]
            assert he_status_txt.text.strip() == "Hosted Engine is up!",    \
                "Hosted engine status not up"

    def check_vm_status(self):
        """
        Purpose:
            Check the host status
        """
        with self.switch_to_frame(self.frame_right_name):
            assert re.search('up', list(self.vm_state_txts)[0].text),   \
                "The VM is not up"

    def check_vm_on_additional_host(self):
        """
        Purpose:
            Check vm on the additional host
        """
        with self.switch_to_frame(self.frame_right_name):
            assert re.search('up', list(self.vm_state_txts)[1].text),   \
                "The VM is not up on the additional host"

    def check_he_running_on_host(self, host_name):
        """
        Purpose:
            Check the hosted engine is running on local host
        """
        with self.switch_to_frame(self.frame_right_name):
            he_running_on_txt = list(self.vcenters)[1]
            assert re.search(host_name, he_running_on_txt.text),     \
                "Hosted engine running on host not correct"

    def put_host_to_local_maintenance(self):
        """
        Purpose:
            Put the host to local maintenance
        """
        with self.switch_to_frame(self.frame_right_name):
            put_host_local_maintenace_btn = list(self.btns)[0]
            put_host_local_maintenace_btn.click()
            self.wait(150)

    def check_host_in_local_maintenance(self):
        """
        Purpose:
            Check the host is in local maintenance
        """
        with self.switch_to_frame(self.frame_right_name):
            host_agent_maintenance_txt = list(
                self.list_group_item_txts)[0].text
            host_maintenance_txt = host_agent_maintenance_txt.split()[-1]
            assert host_maintenance_txt == "true",  \
                "Host is not in local maintenance"

    def check_host_not_in_local_maintenance(self):
        """
        Purpose:
            Check the host is not in local maintenance
        """
        with self.switch_to_frame(self.frame_right_name):
            host_agent_maintenance_txt = list(
                self.list_group_item_txts)[0].text
            host_maintenance_txt = host_agent_maintenance_txt.split()[-1]
            assert host_maintenance_txt == "false",     \
                "Host is in local maintenance"

    def remove_host_from_local_maintenance(self):
        """
        Purpose:
            Remove the host from local maintenance
        """
        with self.switch_to_frame(self.frame_right_name):
            remove_host_local_maintenace_btn = list(self.btns)[1]
            remove_host_local_maintenace_btn.click()
            self.wait(60)

    def put_cluster_to_global_maintenance(self):
        """
        Purpose:
            Put the cluster to global maintenance
        """
        with self.switch_to_frame(self.frame_right_name):
            put_host_local_maintenace_btn = list(self.btns)[2]
            put_host_local_maintenace_btn.click()
            self.wait(10)

    def check_cluster_in_global_maintenance(self):
        """
        Purpose:
            Check whether the cluster is in global maintenance
        """
        with self.switch_to_frame(self.frame_right_name):
            assert self.global_maintenance_div, "The cluster is not in global maintenance"
            #if not self.global_maintenance_div.find(True):
            #    assert 0, "The cluster is not in global maintenance"

    def check_cluster_not_in_global_maintenance(self):
        """
        Purpose:
            Check the cluster is not in global maintenance
        """
        with self.switch_to_frame(self.frame_right_name):
            assert not self.global_maintenance_div, "The cluster is in global maintenance"

    def check_vm_migrated(self):
        """
            Suppose there are only two hosts,
            check the HE vm already migrate to another host
        """
        with self.switch_to_frame(self.frame_right_name):
            vm_state_txt = list(self.vm_state_txts)[1].text
            vm_status = vm_state_txt.split()[-1]
            assert vm_status == "up",  \
                "The HE vm did not migrated to another host"
class ServicePage(PageObject):
    targets_btn = PageElement(xpath=".//*[@id='services-filter']/button[1]")
    sys_service_btn = PageElement(
        xpath=".//*[@id='services-filter']/button[2]")
    sockets_btn = PageElement(xpath=".//*[@id='services-filter']/button[3]")
    timers_btn = PageElement(xpath=".//*[@id='services-filter']/button[4]")
    paths_btn = PageElement(xpath=".//*[@id='services-filter']/button[5]")

    # Elements under the system service button
    test_services_state = MultiPageElement(class_name="service-unit-data")
    test_services_description = MultiPageElement(
        class_name="service-unit-description")

    # Elements after click above service button
    service_title_name = PageElement(xpath=".//*[@id='service']/ol/li[2]")
    service_start_stop_action = PageElement(
        xpath=".//*[@id='service-unit-action']/button[1]")
    service_enable_disable_action = PageElement(
        xpath=".//*[@id='service-file-action']/button[1]")
    service_unit_dropdown_action = PageElement(
        xpath=".//*[@id='service-unit-action']/button[2]")
    service_file_dropdown_action = PageElement(
        xpath=".//*[@id='service-file-action']/button[2]")

    service_restart_action = PageElement(
        xpath=".//*[@id='service-unit-action']/ul/li[3]/a")

    # frame name
    frame_right_name = "cockpit1:localhost/system/services"

    def __init__(self, *args, **kwargs):
        super(ServicePage, self).__init__(*args, **kwargs)
        self.get("/system/services")
        self.wait(5)

    def basic_check_elements_exists(self):
        assert self.targets_btn, "targets button not exists"
        assert self.sys_service_btn, "system service button not exists"
        assert self.sockets_btn, "socket button not exists"
        assert self.timers_btn, "timers button not exists"
        assert self.paths_btn, "paths button not exists"

    def disable_service_action(self):
        with self.switch_to_frame(self.frame_right_name):

            # Get a running service to disable
            for k in range(len(list(self.test_services_state))):
                if re.search("running",
                             list(self.test_services_state)[k].text):
                    running_seq = k
                    break

            list(self.test_services_description)[running_seq].click()
            self.wait(1)

            # Get the running service name and click disable
            service_name = self.service_title_name.text
            self.service_enable_disable_action.click()
            self.wait(1)
            return service_name

    def check_service_is_disabled(self, service_name):
        # Check the service is disabled
        with settings(warn_only=True):
            cmd = "service %s status|grep Loaded" % service_name
            output = run(cmd)
        assert re.search("disabled", output.split(';')[1]),   \
            "Failed to disable %s" % service_name

    def enable_service_action(self):
        with self.switch_to_frame(self.frame_right_name):
            # Click enable button to enable the service
            self.service_enable_disable_action.click()

    def check_service_is_enabled(self, service_name):
        # Check the service is disabled
        with settings(warn_only=True):
            cmd = "service %s status|grep Loaded" % service_name
            output = run(cmd)
        assert re.search("enabled", output.split(';')[1]),   \
            "Failed to enable %s" % service_name

    def stop_service_action(self):
        with self.switch_to_frame(self.frame_right_name):
            # Click enable button to enable the service
            self.service_start_stop_action.click()

    def check_service_is_stoped(self, service_name):
        with settings(warn_only=True):
            cmd = "service %s status|grep Active" % service_name
            output = run(cmd)

        assert re.search("inactive", output),   \
            "Failed to stop %s service" % service_name

    def start_service_action(self):
        with self.switch_to_frame(self.frame_right_name):
            self.service_start_stop_action.click()

    def check_service_is_started(self, service_name):
        with settings(warn_only=True):
            cmd = "service %s status|grep Active" % service_name
            output = run(cmd)

        assert re.search("active", output),   \
            "Failed to start %s service" % service_name

    def restart_service_action(self):
        with self.switch_to_frame(self.frame_right_name):
            self.service_unit_dropdown_action.click()

            # Restart unit action
            self.service_restart_action.click()

    def check_service_is_restarted(self, service_name):
        with settings(warn_only=True):
            cmd = "service %s status|grep Active" % service_name
            output = run(cmd)

        assert re.search("active", output),   \
            "Failed to restart the %s service" % service_name
class NodeStatusPage(PageObject):
    """To check Node status and System info on Virtualization panel."""
    # health_status_btn: click health_status_text link_text
    health_status_btn = PageElement(
        xpath=".//*[@id='content']/div/div/div[1]/table/tbody[2]/tr[1]/td[2]/div[1]/a/div")

    # currentlayer_status_btn: click currentlayer_status_text link_text
    currentlayer_status_btn = PageElement(
        xpath=".//*[@id='content']/div/div/div[1]/table/tbody[2]/tr[2]/td[2]/div[1]/a")

    # rollback_btn: click rollback button
    rollback_btn = PageElement(
        xpath=".//*[@id='content']/div/div/div[1]/table/tbody[2]/tr[2]/td[2]/div[1]/span/button")

    # strong text shown after Virtual Machines
    strong_txt = MultiPageElement(tag_name="strong")

    # page_links: link text after Network info, System log, storage, SSH host key
    page_links = MultiPageElement(link_text="View")

    # accordion_header_btn: like "Thin storage","basic storage","Mount points" button
    accordion_header_btn = MultiPageElement(class_name="accordion-header")
    # close_btn : close button,like "X"
    close_btn = MultiPageElement(class_name="close")

    # elements under Node health dialog
    ok_icons = MultiPageElement(class_name="pficon-ok")

    # elements under Node information dialog
    entry_txts = MultiPageElement(class_name="col-md-6")

    # elements under rollback dialog
    available_layer_txt = MultiPageElement(class_name="col-md-8")

    # elements with warning if login with non-root account
    alert_div_span = PageElement(xpath=".//*[@id='content']/div/div[1]/span")
    alert_div = PageElement(class_name="alert-danger")

    # frame name
    frame_right_name = "cockpit1:localhost/ovirt-dashboard"

    def __init__(self, *args, **kwargs):
        super(NodeStatusPage, self).__init__(*args, **kwargs)
        self.get("/ovirt-dashboard")
        self.wait(5)

    def basic_check_elements_exists(self):
        with self.switch_to_frame(self.frame_right_name):
            assert self.health_status_btn, "Health status btn not exist"
            assert self.currentlayer_status_btn, \
                "Currentlayer status button not exist"
            assert self.rollback_btn, "Rollback btn not exist"
        self.wait()

    def query_host_is_registerd(self, rhvm_fqdn, host_name):
        rhvm_action = RhevmAction(rhvm_fqdn)
        result = rhvm_action.query_host_id_by_name(host_name)
        return result

    def add_host_to_rhvm(self, rhvm_fqdn, host_ip, host_name, host_password):
        rhvm_action = RhevmAction(rhvm_fqdn)
        rhvm_action.add_new_host(host_ip, host_name, host_password)
        self.wait(120)

    def remove_host_from_rhvm(self, rhvm_fqdn, host_name):
        rhvm_action = RhevmAction(rhvm_fqdn)
        rhvm_action.remove_host(host_name)
        self.wait(10)

    def check_virtual_machine(self):
        """
        Purpose:
            Check the virtual Machines in oVirt page
        """
        raise NotImplementedError

    def check_node_status(self):
        """
        Purpose:
            Check node status in virtualization dashboard.
        """
        with self.switch_to_frame(self.frame_right_name):
            assert self.health_status_btn, "Health status btn not exist"
            assert self.currentlayer_status_btn, \
                "Currentlayer status button not exist"
            assert self.rollback_btn, "Rollback btn not exist"
        self.wait()

    def _check_vdsmd_active(self):
        cmd = "systemctl status vdsmd|grep Active"
        output_status = run(cmd)
        status = output_status.split()[1]
        return status

    def check_node_health(self, is_registerd=True):
        """
        Purpose:
            Check node health info in virtualization dashboard
        """
        self.wait()
        with self.switch_to_frame(self.frame_right_name):
            self.health_status_btn.click()
            accordion_header_btn_list = list(self.accordion_header_btn)
            for i in accordion_header_btn_list[0:3]:
                i.click()
            self.wait(10)
            ok_number = len(list(self.ok_icons))

            if is_registerd:
                assert ok_number == 14, "Node health status is error"
            else:
                if self._check_vdsmd_active() == "active":
                    assert ok_number == 14, "Node health status is error"
                else:
                    assert ok_number == 11, "Node health status is error"
            close_btn_list = list(self.close_btn)
            for j in close_btn_list[0:]:
                j.click()

    def check_node_info(self, test_layer):
        """
        Purpose:
            Check node information in virtualization dashboard
        """
        self.wait()
        with self.switch_to_frame(self.frame_right_name):
            self.currentlayer_status_btn.click()
            accordion_header_btn_list = list(self.accordion_header_btn)
            for i in accordion_header_btn_list:
                i.click()
            self.wait(3)

            # Current layer should be identical with the argument
            entry_txt_list = list(self.entry_txts)
            assert entry_txt_list[1].text == test_layer, \
                "Test layer fail"

            # Since no update action on the new fresh installed
            # system, default layer is current layer
            assert entry_txt_list[0].text == entry_txt_list[1].text, \
                "Default is not current layer"

            close_btn_list = list(self.close_btn)
            for j in close_btn_list[0:]:
                j.click()

    def check_node_layer(self, test_layer):
        """
        Purpose:
            Check node layers in virtualization dashboard
        """
        self.wait()
        with self.switch_to_frame(self.frame_right_name):
            self.currentlayer_status_btn.click()
            accordion_header_btn_list = list(self.accordion_header_btn)
            for i in accordion_header_btn_list:
                i.click()
            self.wait(3)

            # Current layer should be identical with the argument
            entry_txt_list = list(self.entry_txts)
            assert entry_txt_list[1].text == test_layer, \
                "Test layer fail"

            # Since no update action on the new fresh installed
            # system, default layer is current layer
            assert entry_txt_list[0].text == entry_txt_list[1].text, \
                "Default is not current layer"

            close_btn_list = list(self.close_btn)
            for j in close_btn_list[0:]:
                j.click()

    def check_node_status_fc(self, test_layer, is_registerd=True):
        """
        Purpose:
            Check node status with FC multipath
        """
        # This will be tested on a rhvh with fc storage
        self.check_node_status()
        self.check_node_health()
        self.check_node_info(test_layer)

    def check_node_status_efi(self, test_layer, is_registerd=True):
        """
        Purpose:
            Check node status with EFI
        """
        self.check_node_status()
        self.check_node_health(is_registerd)
        self.check_node_info(test_layer)

    def check_rollabck_func(self):
        """
        Purpose:
            Rollback funciton in virtualization dashboard
        """
        raise NotImplementedError

    def check_network_func(self):
        """
        Purpose:
            Check the Networking Information in virtualization dashboard
        """
        # Since no network info on cockpit, just drop this case currently
        self.wait()
        with self.switch_to_frame(self.frame_right_name):
            page_links_list = list(self.page_links)
            system_logs_link = page_links_list[0]
            system_logs_link.click()
            self.wait(3)

    def check_system_log(self):
        """
        Purpose:
            Check the System Logs in virtualization dashboard
        """
        self.wait()
        with self.switch_to_frame(self.frame_right_name):
            page_links_list = list(self.page_links)
            system_logs_link = page_links_list[1]
            system_logs_link.click()
            self.wait(3)

    def check_storage(self):
        """
        Purpose:
            Check the Storage in virtualization dashboard
        """
        self.wait()
        with self.switch_to_frame(self.frame_right_name):
            page_links_list = list(self.page_links)
            storage_link = page_links_list[2]
            storage_link.click()
            self.wait(3)

    def check_ssh_key(self):
        """
        Purpose:
            Check the ssh host key in virtualization dashboard
        """
        self.wait()
        with self.switch_to_frame(self.frame_right_name):
            page_links_list = list(self.page_links)
            storage_link = page_links_list[3]
            storage_link.click()
            self.wait(3)

    def check_list_vms(self):
        """
        Purpose:
            List of vms in dashboard
        """
        with self.switch_to_frame(self.frame_right_name):
            cmd = "ps -ef|grep qemu-kvm|grep -v grep|wc -l"
            output = run(cmd)
            vm_count = int(output)
            assert int(list(self.strong_txt)[0].text) == vm_count, \
                "VM count not correct"
        self.wait()

    def check_non_root_alert(self, default=False):
        """
        Purpose:
            Check if login with non-root account, if yes, there
            will be a alert div
        """
        with self.switch_to_frame(self.frame_right_name):
            if default:
                try:
                    assert self.alert_div,  \
                        "Can't check node status! Please run as administrator not exists"
                except Exception as e:
                    assert False, "Can't check node status! Please run as administrator not exists"
class SubscriptionsPage(PageObject):
    """Subscription-manager for host to register to RHSM/Satellite server"""

    ######################

    register_sys_btn = PageElement(tag_name="button")
    login_input = PageElement(id_="subscription-register-username")
    passwd_input = PageElement(id_="subscription-register-password")
    key_input = PageElement(id_="subscription-register-key")
    org_input = PageElement(id_="subscription-register-org")

    btns = MultiPageElement(tag_name="button")

    # url = PageElement(id_="subscription-register-url")
    url_select_btn = PageElement(
        xpath=".//*[@id='subscription-register-url']/button")
    url_default_item = PageElement(
        xpath=".//*[@id='subscription-register-url']/ul/li[1]/a")
    url_custom_item = PageElement(
        xpath=".//*[@id='subscription-register-url']/ul/li[2]/a")
    url_input = PageElement(id_="subscription-register-url-custom")

    installed_product_btn = PageElement(tag_name="th")
    spans = MultiPageElement(tag_name="span")

    # frame name
    frame_right_name = "cockpit1:localhost/subscriptions"

    def __init__(self, *args, **kwargs):
        super(SubscriptionsPage, self).__init__(*args, **kwargs)
        self.get("/subscriptions")
        self.wait(10)

    def basic_check_elements_exists(self):
        with self.switch_to_frame(self.frame_right_name):
            assert self.register_sys_btn, "register system btn not exist"
            assert self.login_input, "login text editor not exist"
            assert self.passwd_input, "password text editor not exist"
            assert self.submit_btn, "register button not exist"
            assert self.key_input, "Activation Key text editor not exist"
            assert self.org_input, "Organization text editor not exist"
            assert self.url_select_btn, "Url select btn not exist"
            assert self.url_default_item, "default item in url list not exist"
            assert self.url_custom_item, "custom item in url list not exist"
            assert self.url_input, "url text editor not exist"

    def check_register_rhsm(self, rhn_user, rhn_password):
        """
        Purpose:
            Test subscription to RHSM
        """
        with self.switch_to_frame(self.frame_right_name):
            self.register_sys_btn.click()
            self._clean_all()
            self.url_select_btn.click()
            self.url_custom_item.click()
            self.wait(0.5)
            self.login_input.send_keys(rhn_user)
            self.wait(0.5)
            self.passwd_input.send_keys(rhn_password)
            self.wait(0.5)

            submit_btn = list(self.btns)[3]
            submit_btn.click()
            self.wait(60)

    def check_register_rhsm_key_org(self, activation_key, activation_org):
        """
        Purpose:
            Test subscription to RHSM with key and organization
        """
        with self.switch_to_frame(self.frame_right_name):
            self.register_sys_btn.click()
            self._clean_all()
            self.url_select_btn.click()
            self.url_custom_item.click()
            self.wait(0.5)
            self.key_input.send_keys(activation_key)
            self.wait(0.5)
            self.org_input.send_keys(activation_org)
            self.wait(0.5)

            submit_btn = list(self.btns)[3]
            submit_btn.click()
            self.wait(60)

    def check_register_satellite(self, satellite_ip, satellite_user,
                                 satellite_password):
        """
        Purpose:
            RHEVM-16752
            Test subscription to Satellite server
        """
        with self.switch_to_frame(self.frame_right_name):
            self.register_sys_btn.click()
            self._clean_all()
            self.url_select_btn.click()
            self.url_custom_item.click()
            self.wait(0.5)
            self.url_input.send_keys(satellite_ip + "/rhsm")
            self.wait(0.5)
            self.login_input.send_keys(satellite_user)
            self.wait(0.5)
            self.passwd_input.send_keys(satellite_password)
            self.wait(0.5)
            self.submit_btn.click()
            self.wait(60)

    def check_password_encrypted(self, rhn_password):
        """
        Purpose:
            RHEVM-16750
            Test check password is encrypted in rhsm.log
        """
        remote_path = "/var/log/rhsm/rhsm.log"
        fd = StringIO()
        get(remote_path, fd)
        content = fd.getvalue()
        assert not re.search(
            rhn_password, content), "There is plain password in rhsm.log file"

    def check_subscription_result(self):
        with self.switch_to_frame(self.frame_right_name):
            self.installed_product_btn.click()
            self.wait(1)
            product_name = list(self.spans)[0]
            register_status = list(self.spans)[4]
            print product_name.text, register_status.text
            assert product_name.text == "Red Hat Virtualization Host", \
                "product name is wrong"
            assert register_status.text == "Subscribed", \
                "subscription fail"

    def unregister_subsciption(self):
        cmd = 'subscription-manager unregister'
        subscripted = run(cmd)
        self.wait(5)
        if subscripted != "System has been unregistered":
            self.wait(5)

    def ca_install(self, ca_path):
        cmd_download_ca = "curl -O -k " + ca_path
        run(cmd_download_ca)
        self.wait(5)
        cmd_install_ca = "rpm -Uvh " + os.path.basename(ca_path)
        run(cmd_install_ca)
        self.wait(10)

    def add_domain_name(self, ip, hostname):
        append_txt = ip + '  ' + hostname
        cmd_dns = "echo " + append_txt + " >> /etc/hosts"
        run(cmd_dns)

    def _clean_all(self):
        self.login_input.clear()
        self.passwd_input.clear()
        self.key_input.clear()
        self.org_input.clear()

    def reset(self, ca_path):
        cmd_rpm_qa = "rpm -qa|grep katello"
        result = run(cmd_rpm_qa)
        if result:
            cmd = "rpm -e " + os.path.splitext(os.path.basename(ca_path))[0]
            run(cmd)
            self.wait()
class AccountPage(PageObject):
    accounts_create_btn = PageElement(id_="accounts-create")
    cockpit_accounts_div = MultiPageElement(class_name="cockpit-account")

    # Elements after click the accounts create page
    real_name_input = PageElement(id_="accounts-create-real-name")
    user_name_input = PageElement(id_="accounts-create-user-name")
    password_input = PageElement(id_="accounts-create-pw1")
    confirm_input = PageElement(id_="accounts-create-pw2")
    access_checkbox = PageElement(id_="accounts-create-locked")
    create_btn = PageElement(id_="accounts-create-create")

    # Elements after click the cockpit-accounts-div
    account_username = PageElement(id_="account-user-name")
    account_delete = PageElement(id_="account-delete")

    # Elements after click the Delete button
    delete_files_checkbox = PageElement(id_="account-confirm-delete-files")
    delete_apply_btn = PageElement(id_="account-confirm-delete-apply")

    # frame name
    frame_right_name = "cockpit1:localhost/users"

    def __init__(self, *args, **kwargs):
        super(AccountPage, self).__init__(*args, **kwargs)
        self.get("/users")
        self.wait(5)

    def basic_check_elements_exists(self):
        with self.switch_to_frame(self.frame_right_name):
            assert self.accounts_create_btn, "account create button not exists"
            assert self.cockpit_account_div, "cockpit account div not exists"

    def create_new_account(self):
        """
        Purpose:
            Create a new account via cockpit
        """
        with self.switch_to_frame(self.frame_right_name):
            self.accounts_create_btn.click()
            self.wait(1)
            self.real_name_input.clear()
            self.wait(1)
            self.real_name_input.send_keys("cockpit")
            self.wait(3)

            self.user_name_input.clear()
            self.wait(1)
            self.user_name_input.send_keys("cockpit")
            self.wait(3)

            self.password_input.clear()
            self.wait(1)
            self.password_input.send_keys("cockpitauto")
            self.wait(3)

            self.confirm_input.clear()
            self.wait(1)
            self.confirm_input.send_keys("cockpitauto")
            self.wait(3)

            self.create_btn.click()

    def check_new_account_from_ssh(self, host_ip):
        """
        Purpose:
            Check the host can be accessed via new account
        """
        cmd = "whoami"
        local_current_user = local(cmd, capture=True)
        print local_current_user
        cmd = "rm -f /home/%s/.ssh/know_hosts" % local_current_user
        local(cmd)
        """
        with settings(
            host_string="cockpit@" + host_ip,
                password="******"):
            output = run("whoami")
            assert re.search("cockpit", output), \
                "New account can not be accessed via ssh"
        """
        with settings(warn_only=True):
            output = sudo("whoami", user="******")
            assert re.search("cockpit", output), \
                "New account can not be accessed via ssh"

    def delete_new_account(self):
        """
        Purpose:
            Delete the new created account
        """
        with self.switch_to_frame(self.frame_right_name):
            for each_account in list(self.cockpit_accounts_div):
                each_account.click()
                if re.search("cockpit", self.account_username.text):
                    self.account_delete.click()
                    self.wait(1)
                    self.delete_files_checkbox.click()
                    self.wait(1)
                    self.delete_apply_btn.click()
                    self.wait(1)
                    break
                assert not re.search(
                    "cockpit", self.account_username.text),     \
                    "Failed to delete the account"
class SystemPage(PageObject):
    brand_log = PageElement(id_="index-brand")
    machine_link = PageElement(
        xpath=".//*[@id='machine-link']/span")
    hostname_btn = PageElement(
        id_="system_information_hostname_button")
    systime_btn = PageElement(
        id_="system_information_systime_button")
    performance_profile_btn = PageElement(class_name="action-trigger")

    # Elements after click the hostname_btn
    pretty_hostname_input = PageElement(id_="sich-pretty-hostname")
    real_hostname_input = PageElement(id_="sich-hostname")
    set_hostname_apply_btn = PageElement(id_="sich-apply-button")

    # Elements after click the systime_btn
    timezone_input = PageElement(class_name="form-control")
    set_time_btn = PageElement(class_name="btn-default")
    set_time_apply_btn = PageElement(id_="systime-apply-button")

    # Elements after click performance profile button
    performance_profiles = MultiPageElement(class_name="list-group-item")
    performance_apply_btn = PageElement(class_name="btn-primary")

    # frame name
    frame_right_name = "cockpit1:localhost/system"

    def __init__(self, *args, **kwargs):
        super(SystemPage, self).__init__(*args, **kwargs)
        self.get("/system")
        self.wait(5)

    def basic_check_elements_exists(self):
        assert self.brand_log, "brand-log not exist"
        self.wait(2)

    def check_login_host(self, host_ip):
        assert re.search(host_ip, self.machine_link.text),   \
            "%s not login" % host_ip

    def configure_hostname(self):
        """
        Purpose:
            Configure hostname on system page
        """
        with self.switch_to_frame(self.frame_right_name):
            self.hostname_btn.click()
            self.wait(1)
            self.pretty_hostname_input.send_keys("cockpitauto")
            self.real_hostname_input.clear()
            self.wait(1)
            self.real_hostname_input.send_keys("cockpitauto.redhat.com")
            self.wait(1)
            self.set_hostname_apply_btn.click()
            self.wait(1)

    def check_configure_hostname(self):
        """
        Purpose:
            Check the hostname were changed
        """
        with self.switch_to_frame(self.frame_right_name):
            assert re.search(
                "cockpitauto.redhat.com",
                self.hostname_btn.text),    \
                "Configure hostname failed"

        with settings(warn_only=True):
            cmd = "hostname"
            output = run(cmd)
            assert re.search("cockpitauto.redhat.com", output),    \
                "Configure hostname failed"

    def configure_timezone(self):
        """
        Purpose:
            Configure timezone on system page
        """
        with self.switch_to_frame(self.frame_right_name):
            self.systime_btn.click()
            self.wait(3)

            self.timezone_input.clear()
            self.wait(1)
            self.timezone_input.send_keys("America/Los_Angeles")
            self.wait(1)
            self.set_time_apply_btn.click()

    def check_configure_timezone(self):
        """
        Purpose:
            Check time were configured as needed
        """
        with settings(warn_only=True):
            cmd = "timedatectl|grep 'Time zone'"
            output = run(cmd)
            assert re.search("America/Los_Angeles", output),    \
                "Configure hostname failed"

    def configure_time(self):
        """
        Purpose:
            Configure time on system page
        """
        with self.switch_to_frame(self.frame_right_name):
            self.systime_btn.click()
            self.wait(1)

            # To do
            pass

    def check_configure_time(self):
        """
        Purpose:
            Check the time were configured as needed
        """
        with settings(warn_only=True):
            # To do
            pass

    def change_performance_profile(self):
        """
        Purpose:
            Change the performance profile
        """
        with self.switch_to_frame(self.frame_right_name):
            self.performance_profile_btn.click()
            self.wait(1)

            list(self.performance_profiles)[1].click()
            self.wait(0.5)
            self.performance_profile_btn.click()
            self.wait(1)

    def check_change_performance_profile(self):
        """
        Purpose:
            Check the profile is changed
        """
        with settings(warn_only=True):
            cmd = "tuned-adm active"
            output = run(cmd)

            assert re.search("balanced", output),   \
                "The profile is not changed"
Esempio n. 19
0
class VirtualMachinesPage(PageObject):
    """
    Function:
        Inspect virtual machines which managed by RHEVM in cockpit WebUI
    """
    content_username_txt = PageElement(id_="content-user-name")
    logout_link = PageElement(id_="go-logout")

    running_vms_btn = PageElement(id_="main-btn-menu-hostvms")
    vms_in_cluster_btn = PageElement(id_="main-btn-menu-allvms")
    vdsm_btn = PageElement(id_="main-btn-menu-vdsm")

    technical_preview_text = PageElement(
        xpath=".//*[@id='ovirt-content']/table/tbody/tr/td[2]/div")
    engine_login_link = PageElement(id_="engine-login-title")
    maintenance_host_link = PageElement(link_text="Host to Maintenance")
    refresh_link = PageElement(partial_link_text="Refresh")
    engine_login_passwd_input = PageElement(id_="engine-login-pwd")
    engine_login_url_input = PageElement(id_="engine-login-url")
    engine_login_submit_btn = PageElement(id_="modal-engine-login-form-dologin")

    virtual_machines_title = PageElement(
        xpath=".//*[@id='virtual-machines']/div[1]/div/div[1]/h3")
    total_vms_text = PageElement(id_="host-vms-total")
    vdsm_unactived_textblock = PageElement(id_="vdsm-is-not-active")

    # VM elements
    vm_hostname_links = MultiPageElement(
        xpath=".//*[@id='host-vms-list-item-name-']/a")
    vm_guest_ip_txts = MultiPageElement(
        xpath=".//*[@id='host-vms-list-item-name-']/small[1]")
    vm_hostname_txts = MultiPageElement(
        xpath=".//*[@id='host-vms-list-item-name-']/small[2]")
    vm_up_txts = MultiPageElement(
        xpath=".//*[@id='host-vms-list-item-name-']/small[3]")
    vm_lifecycle_btns = MultiPageElement(tag_name="button")
    vm_lifecycle_operations = MultiPageElement(tag_name="li")

    # Elements under detail of VM
    name_first_row_second_column = PageElement(
        xpath=".//*[@id='vm-detail-content']/div[2]/table/tbody/tr/td/table/tbody/tr[1]/td[2]")
    ip_first_row_fourth_column = PageElement(
        xpath=".//*[@id='vm-detail-content']/div[2]/table/tbody/tr/td/table/tbody/tr[1]/td[4]")
    id_second_row_second_column = PageElement(
        xpath=".//*[@id='vm-detail-content']/div[2]/table/tbody/tr/td/table/tbody/tr[2]/td[2]")
    vcpu_second_row_fourth_column = PageElement(
        xpath=".//*[@id='vm-detail-content']/div[2]/table/tbody/tr/td/table/tbody/tr[2]/td[4]")
    username_third_row_second_column = PageElement(
        xpath=".//*[@id='vm-detail-content']/div[2]/table/tbody/tr/td/table/tbody/tr[3]/td[2]")
    uptime_third_row_fourth_column = PageElement(
        xpath=".//*[@id='vm-detail-content']/div[2]/table/tbody/tr/td/table/tbody/tr[3]/td[4]")
    display_fourth_row_second_column = PageElement(
        xpath=".//*[@id='vm-detail-content']/div[2]/table/tbody/tr/td/table/tbody/tr[4]/td[2]")
    fqdn_fourth_row_fourth_column = PageElement(
        xpath=".//*[@id='vm-detail-content']/div[2]/table/tbody/tr/td/table/tbody/tr[4]/td[4]")
    app_fifth_row_second_column = PageElement(
        xpath=".//*[@id='vm-detail-content']/div[2]/table/tbody/tr/td/table/tbody/tr[5]/td[4]")

    # VDSM related elements
    vdsm_service_management_link = PageElement(
        link_text="VDSM Service Management")
    vdsm_conf_textarea = PageElement(id_="editor-vdsm-conf")
    vdsm_save_btn = PageElement(id_="editor-vdsm-btn-save")
    vdsm_reload_btn = PageElement(id_="editor-vdsm-btn-reload")

    vdsm_config_dialog_title = PageElement(id_="modal-confirmation-title")
    vdsm_config_dialog_close_btn = PageElement(class_name="close")
    vdsm_config_dialog_text = PageElement(id_="modal-confirmation-text")
    vdsm_config_dialog_ok = PageElement(id_="modal-confirmation-ok")
    vdsm_config_dialog_cancel = PageElement(
        xpath=".//*[@id='modal-confirmation']/div/div/div[3]/button[1]")
    vdsm_config_dialog_saved = PageElement(id_="editor-vds-conf-msg")

    # sub-frame name
    frame_right_name = "cockpit1:localhost/ovirt-dashboard"

    def __init__(self, *args, **kwargs):
        super(VirtualMachinesPage, self).__init__(*args, **kwargs)
        self.get("/ovirt-dashboard#/management")
        self.wait(10)

    def basic_check_elements_exists(self):
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            assert self.running_vms_btn, "Running VMs button is missing"
            assert self.vms_in_cluster_btn, "VMs in cluster button is missing"
            assert self.vdsm_btn, "VDSM button is missing"
            assert self.engine_login_link, "Login to engine link is missing"
            assert self.maintenance_host_link,  \
                "Host to maintenance link is missing"
            assert self.refresh_link, "Refresh link is missing"

    def check_running_vms_unregister(self):
        """
        Purpose:
            Check running VMs (Unregister to RHEVM)
            status in virtual machines page
        """
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))

            assert re.search("Virtual Machines", self.virtual_machines_title.text),  \
                "Running VMs page title is wrong"
            assert self.total_vms_text.text == "0", "Total VMs number is displayed wrong"

            target_textblock = "The VDSM service is not responding on this host"

            assert re.search(target_textblock, self.vdsm_unactived_textblock.text), \
            "The VDSM service is responding on this host"

    def check_vms_in_cluster_unregister(self):
        """
        Purpose:
            Check VMs in cluster (Unregister to RHEVM)
            status in virtual machines page
        """
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            self.vms_in_cluster_btn.click()
            self.wait(1)
            try:
                assert self.w.switch_to_alert()
            except NoAlertPresentException as e:
                raise e

    def check_running_vms_register(
        self,
        he_vm_fqdn,
        he_vm_ip,
        he_password,
        second_vm_fqdn):
        """
        Purpose:
            Check running VMs (Register to RHEVM) status
            Suppose this VM is Hosted Engine and another common VM
        """
        # Delete the previous screenshot of the VM page
        with settings(warn_only=True):
            cmd1 = "rm -f /tmp/cockpit_auto/running_vms.png"
            run(cmd1)
            cmd2 = "rm -f /tmp/cockpit_auto/he_vm_detail.png"
            run(cmd2)
            cmd3 = "rm -f /tmp/cockpit_auto/common_vm_detail.png"
            run(cmd3)

        # Screenshot of the VM page
        self.save_screenshot("running_vms.png")

        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))

            # To Do: Need to check the accurate up time
            assert self.vm_up_txts, "VM up time text not exists"

            he_vm_sequence_num = 0
            common_vm_sequence_num = 1
            # Check HostedEngine VM and common vm without any guest OS
            for k, hostname_link in enumerate(list(self.vm_hostname_links)):
                if re.search("HostedEngine", hostname_link.text):
                    if k == 1:
                        common_vm_sequence_num = 0
                    he_vm_sequence_num = k

                    assert re.search(he_vm_ip, list(self.vm_guest_ip_txts)[k].text),    \
                        "HE Guest IP text not correct"
                    assert re.search(he_vm_fqdn, self.vm_hostname_txts[k].text),    \
                        "HE hostname text not correct"
                else:
                    re.search(second_vm_fqdn, list(self.vm_hostname_links)[k].text),     \
                        "Second VM name not correct"

            # Click to check the detail info of the HE vm
            list(self.vm_hostname_links)[he_vm_sequence_num].click()

            self.save_screenshot("he_vm_detail.png")
            assert re.search(
                "HostedEngine", self.name_first_row_second_column.text) # HostedEngine

            assert re.search(
                he_vm_ip, self.ip_first_row_fourth_column.text) # HE vm ip

            cmd = "cat /proc/cpuinfo|grep processor|wc -l"
            with settings(
                warn_only=True,
                host_string='root@' + he_vm_ip,
                password=he_password):
                vcpu_count = run(cmd)
            assert re.search(
                vcpu_count, self.vcpu_second_row_fourth_column.text) # VCPU count

            assert re.search(
                "None", self.username_third_row_second_column.text) # Username
            '''
            assert re.search(
                "vnc", self.display_fourth_row_second_column.text) # Display type
            '''
            assert re.search(
                he_vm_fqdn, self.fqdn_fourth_row_fourth_column.text) # FQDN

            # Click to screenshot the detail of common VM
            list(self.vm_hostname_links)[common_vm_sequence_num].click()
            self.wait(2)
            self.save_screenshot("/tmp/common_vm_detail.png")

    def check_vms_lifecycle(self):
        """
        Purpose:
            Check life-cycle of VMs in virtual machines page
            Suppose this VM is Hosted Engine
        """
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            assert self.vm_lifecycle_btn, "VM lifecycle button not exists"
            assert self.vm_lifecycle_btn.click()

            assert self.vm_lifecycle_operations,    \
                "VM lifecycle operations buttons not exist"

            # TO Do: operation like restart, force off
            pass

    def check_vdsm_elements(self):
        """
        Purpose:
            Check vdsm page elements exist
        """
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            self.vdsm_btn.click()
            assert self.vdsm_service_management_link,   \
                "The VDSM service management link is missing"
            assert self.vdsm_conf_textarea, \
                "The VDSM config editor is missing"
            assert self.vdsm_save_btn,  \
                "The VDSM config editor save button is missing"
            assert self.vdsm_reload_btn,    \
                "The VDSM config editor reload button is missing"

    def check_vdsm_conf_edit(self):
        """
        Purpose:
            Check vdsm textarea is editable
        """
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            self.vdsm_btn.click()
            self._edit_vdsm_conf("#some_text")
            assert self.vdsm_conf_textarea.get_attribute('value').endswith("some_text"),    \
                "Edit vdsm.conf textarea failed"
            self.wait(1)
            self._vdsm_conf_confirm(self.vdsm_reload_btn)
            self._vdsm_conf_confirm(self.vdsm_save_btn)
            if not self._check_vdsm_conf_host():
                print "edit operation is successful"

            # TODO: Add VDSM service Management link testing
            pass

    def check_vdsm_conf_save(self):
        """
        Purpose:
            Check save function of vdsm page
        """
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            self.vdsm_btn.click()
            if self.vdsm_save_btn:
                self._check_vdsm_config_dialog(self.vdsm_save_btn)

    def check_vdsm_conf_reload(self):
        """
        Purpose:
            Check reload function of vdsm page
        """
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            self.vdsm_btn.click()
            if self.vdsm_reload_btn:
                self._check_vdsm_config_dialog(self.vdsm_reload_btn)

    def _edit_vdsm_conf(self, input):
        """
        Purpose:
            Append text to vdsm.conf
        """
        self.vdsm_conf_textarea.send_keys(input)

    def _check_vdsm_config_dialog(self, button):
        """
        Purpose:
            Check dialogue in vdsm page
        """
        button.click()
        self.wait(1)
        if button.text == 'Save':
            assert re.search("Save to vdsm.conf", self.vdsm_config_dialog_title.get_attribute('innerHTML')),    \
                "Dialogue is not save to vdsm.conf"
            assert self.vdsm_config_dialog_text.get_attribute('innerHTML').startswith("Content of vdsm.conf file will be replaced."),\
                "Dialogue text is wrong!"
        elif button.text == "Reload":
            assert re.search("Reload stored vdsm.conf", self.vdsm_config_dialog_title.\
                get_attribute('innerHTML')), "Dialogue is not reload stored vdsm.conf"
            assert self.vdsm_config_dialog_text.get_attribute('innerHTML').startswith(\
                "Content of vdsm.conf will be reloaded, unsaved changes will be lost."), "Dialogue text is wrong!"
        assert self.vdsm_config_dialog_ok, "Save button is missing in the dialogue"
        assert self.vdsm_config_dialog_cancel, "Cancel button is missing in the dialogue"

        if self.vdsm_config_dialog_cancel.click():
            self.wait(1)
            print "The function of cancel button in vdsm.conf dialogue is invalid"
            self.wait(1)
        else:
            self.wait(1)
        button.click()
        self.wait(1)
        if self.vdsm_config_dialog_ok.click():
            self.wait(1)
            print "The function of cancel button in vdsm.conf dialogue is invalid"
            self.wait(1)
        else:
            self.wait(1)
            if button.text == 'Save':
                assert re.search("Saved", self.vdsm_config_dialog_saved.text), \
                "Save to vdsm.conf failed"
            elif button.text == 'Reload':
                assert re.search("Loaded", self.vdsm_config_dialog_saved.text), \
                "Load to vdsm.conf failed"
            self.wait(5)
            assert re.search("", self.vdsm_config_dialog_saved.text)

    def _vdsm_conf_confirm(self, button):
        """
        Purpose:
            Confirm dialogue
        """
        button.click()
        self.wait(1)
        self.vdsm_config_dialog_ok.click()
        self.wait(2)

    def _check_vdsm_conf_host(self):
        """
        Purpose:
            Check vdsm config file on remote host
        """
        remote_path = "/etc/vdsm/vdsm.conf"
        fd = StringIO()
        get(remote_path, fd)
        content = fd.getvalue()
        assert not re.search("#some_text", content),   \
            "Edit & Save vdsm.conf failed"

    def check_vm_login_to_engine(self, he, he_password):
        """
        Purpose:
            Check the function to click the login to engine
            Suppose the VM is "HOSTED ENGINE"
        """
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            # Click the engine login link
            self.engine_login_link.click()
            self.wait(1)

            # Input engine login password
            self.engine_login_passwd_input.clear()
            self.wait(1)
            self.engine_login_passwd_input.send_keys(he_password)

            # Input the HE url
            he_url = "https://" + he + "/ovirt-engine"
            self.engine_login_url_input.clear()
            self.wait(1)
            self.engine_login_url_input.send_keys(he_url)

            # Submit to login HE
            self.engine_login_submit_btn.click()
            self.wait(5)

            assert re.search("Logout from Engine", self.engine_login_link.text),    \
                "Failed to login Engine"

    def check_vm_logout_from_engine(self):
        """
        Purpose:
            Check the function to click the login to engine
            Suppose the VM is "HOSTED ENGINE"
        """
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            # Ensure it had been login to engine
            assert re.search("Logout from Engine", self.engine_login_link.text),     \
                "No need to logout from engine"

            # Click the engine login link
            self.engine_login_link.click()
            self.wait(1)

            assert re.search("Login to Engine", self.engine_login_link.text),  \
                "Failed to logout from Engine"

    def check_vm_host_to_maintenance(self):
        """
        Purpose:
            Check Host to Maintenance in virtual machines page
        """
        pass

    def check_vm_refresh(self):
        """
        Purpose:
            Check Refrash in virtual machines page
        """
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            print self.refresh_link.text
            if re.search("Refresh: auto", self.refresh_link.text):
                    self.refresh_link.click()
                    self.wait(2)
                    print self.refresh_link.text
                    assert re.search("Refresh: off", self.refresh_link.text),   \
                        "Refresh click not switch to off"
            else:
                self.refresh_link.click()
                self.wait(2)
                print self.refresh_link.text
                assert re.search("Refresh: auto", self.refresh_link.text),    \
                    "Refresh click not switch to auto"

    def logout_from_cockpit(self):
        """
        Purpose:
            Logout from cockpit
        """
        self.content_username_txt.click()
        self.wait(0.5)
        self.logout_link.click()
        self.wait(0.5)
class VirtualMachinesPage(PageObject):
    """
    Function:
        Inspect virtual machines which managed by RHEVM in cockpit WebUI
    """

    running_vms_btn = PageElement(id_="main-btn-menu-hostvms")
    vms_in_cluster_btn = PageElement(id_="main-btn-menu-allvms")
    vdsm_btn = PageElement(id_="main-btn-menu-vdsm")

    technical_preview_text = PageElement(xpath=".//*[@id='ovirt-content']/table/tbody/tr/td[2]/div")
    engine_login_link = PageElement(link_text="Login to Engine")
    maintenance_host_link = PageElement(link_text="Host to Maintenance")
    refresh_link = PageElement(partial_link_text="Refresh")

    virtual_machines_title = PageElement(xpath=".//*[@id='virtual-machines']/div[1]/div/div[1]/h3")
    total_vms_text = PageElement(id_="host-vms-total")
    vdsm_unactived_textblock = PageElement(id_="vdsm-is-not-active")

    vdsm_service_management_link = PageElement(link_text="VDSM Service Management")
    vdsm_conf_textarea = PageElement(id_="editor-vdsm-conf")
    vdsm_save_btn = PageElement(id_="editor-vdsm-btn-save")
    vdsm_reload_btn = PageElement(id_="editor-vdsm-btn-reload")

    vdsm_config_dialog_title = PageElement(id_="modal-confirmation-title")
    vdsm_config_dialog_close_btn = PageElement(class_name="close")
    vdsm_config_dialog_text = PageElement(id_="modal-confirmation-text")
    vdsm_config_dialog_ok = PageElement(id_="modal-confirmation-ok")
    vdsm_config_dialog_cancel = PageElement(xpath=".//*[@id='modal-confirmation']/div/div/div[3]/button[1]")
    vdsm_config_dialog_saved = PageElement(id_="editor-vds-conf-msg")
    
    #sub-frame name
    frame_right_name = "cockpit1:localhost/ovirt-dashboard"

    def __init__(self, *args, **kwargs):
        super(VirtualMachinesPage, self).__init__(*args, **kwargs)
        self.get("/ovirt-dashboard#/management")
        self.wait(period=10)

        self.rhevm_action_obj = RhevmAction(rhevm_fqdn)

    def basic_check_elements_exists(self):
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            assert self.running_vms_btn, "Running VMs button is missing"
            assert self.vms_in_cluster_btn, "VMs in cluster button is missing"
            assert self.vdsm_btn, "VDSM button is missing"
            assert self.engine_login_link, "Login to engine link is missing"
            assert self.maintenance_host_link, "Host to maintenance link is missing"
            assert self.refresh_link, "Refresh link is missing"

    # function_1: Check vms when host unregister to RHEVM
    def check_running_vms_unregister(self):
        """
        Purpose:
            RHEVM-17065
            Check running VMs (Unregister to RHEVM) status in virtual machines page
        """
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            assert re.search("Virtual Machines", self.virtual_machines_title.text),\
             "Running VMs page title is wrong"
            assert self.total_vms_text.text == "0", "Total VMs number is displayed wrong"
            target_textblock = "The VDSM service is not responding on this host"
            assert re.search(target_textblock, self.vdsm_unactived_textblock.text), \
            "The VDSM service is responding on this host"

    # function_2: Check vms in cluster when host unregister to RHEVM
    def check_vms_in_cluster_unregister(self):
        """
        Purpose:
            RHEVM-17066
            Check VMs in cluster (Unregister to RHEVM) status in virtual machines page
        """
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            self.vms_in_cluster_btn.click()
            self.wait(period=1)
            try:
                assert self.w.switch_to_alert()
            except NoAlertPresentException as e: 
                raise e
    
    # function_3: Check vms when host register to RHEVM
    # def check_running_vms_register(self):
    #     """
    #     Purpose:
    #         RHEVM-16607
    #         Check running VMs(local storage disk image) status in virtual machines page
    #     """
    #     with self.switch_to_frame(self.frame_right_name):
    #         self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
    #         # if self.rhevm_action_obj:
    #         #     if self.rhevm_action_obj.add_new_host(*rhvh_credentials):
    #         #         print 'Host regitst to RHEVM successfully'
    #         #         if self.rhevm_action_obj.add_nfs_data_storage(*rhvh_nfs):
    #         #             self.rhevm_action_obj.create_vm("vm_1")
    #         #         else:
    #         #             print "Add nfs data storage failed"
    #         #     else:
    #         #         print "Add new host failed"
    #         # else:
    #         #     print "Create rhevm_action object failed"
    #         self.rhevm_action_obj.create_vm("vm1")


    # function_3: Check vdsm page elements are exist
    def check_vdsm_elements(self):
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            self.vdsm_btn.click()
            assert self.vdsm_service_management_link, "The VDSM service management link is missing"
            assert self.vdsm_conf_textarea, "The VDSM config editor is missing"
            assert self.vdsm_save_btn, "The VDSM config editor save button is missing"
            assert self.vdsm_reload_btn, "The VDSM config editor reload button is missing"

    # function_4: Check vdsm textarea is editable
    def check_vdsm_conf_edit(self):
        """
        Purpose:
            RHEVM-16610
            Check VDSM info in virtual machines page
        """
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            self.vdsm_btn.click()
            self._edit_vdsm_conf(str_input)
            assert self.vdsm_conf_textarea.get_attribute('value').endswith("some_text"), \
            "Edit vdsm.conf textarea failed"
            self.wait(period=1)
            self._vdsm_conf_confirm(self.vdsm_reload_btn)
            self._vdsm_conf_confirm(self.vdsm_save_btn)
            if not self._check_vdsm_conf_host():
                print "edit operation is successful"
            #TODO: Add VDSM service Management link testing

    # function_5: Check save function of vdsm page
    def check_vdsm_conf_save(self):
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            self.vdsm_btn.click()
            if self.vdsm_save_btn:
                self._check_vdsm_config_dialog(self.vdsm_save_btn)
    
    # function_6: Check reload function of vdsm page
    def check_vdsm_conf_reload(self):
        with self.switch_to_frame(self.frame_right_name):
            self.w.switch_to_frame(self.w.find_element_by_tag_name("iframe"))
            self.vdsm_btn.click()
            if self.vdsm_reload_btn:
                self._check_vdsm_config_dialog(self.vdsm_reload_btn)

    # function_7: Append text to vdsm.conf
    def _edit_vdsm_conf(self, input):
        self.vdsm_conf_textarea.send_keys(input)

    # function_8: Check dialogue in vdsm page
    def _check_vdsm_config_dialog(self, button):
        button.click()
        self.wait(period=1)
        if button.text == 'Save':
            assert re.search("Save to vdsm.conf", self.vdsm_config_dialog_title.\
                get_attribute('innerHTML')), "Dialogue is not save to vdsm.conf"
            assert self.vdsm_config_dialog_text.get_attribute('innerHTML').startswith(\
                "Content of vdsm.conf file will be replaced."), "Dialogue text is wrong!"
        elif button.text == "Reload":
            assert re.search("Reload stored vdsm.conf", self.vdsm_config_dialog_title.\
                get_attribute('innerHTML')), "Dialogue is not reload stored vdsm.conf"
            assert self.vdsm_config_dialog_text.get_attribute('innerHTML').startswith(\
                "Content of vdsm.conf will be reloaded, unsaved changes will be lost."), "Dialogue text is wrong!"
        assert self.vdsm_config_dialog_ok, "Save button is missing in the dialogue"
        assert self.vdsm_config_dialog_cancel, "Cancel button is missing in the dialogue"
            
        if self.vdsm_config_dialog_cancel.click():
            self.wait(period=1)
            print "The function of cancel button in vdsm.conf dialogue is invalid"
            self.wait(period=1)
        else:
            self.wait(period=1)
        button.click()
        self.wait(period=1)
        if self.vdsm_config_dialog_ok.click():
            self.wait(period=1)
            print "The function of cancel button in vdsm.conf dialogue is invalid"
            self.wait(period=1)
        else:
            self.wait(period=1)
            if button.text == 'Save':
                assert re.search("Saved", self.vdsm_config_dialog_saved.text), \
                "Save to vdsm.conf failed"
            elif button.text == 'Reload':
                assert re.search("Loaded", self.vdsm_config_dialog_saved.text), \
                "Load to vdsm.conf failed"
            self.wait(period=5)
            assert re.search("", self.vdsm_config_dialog_saved.text)
    
    # function_8: confirm dialogue
    def _vdsm_conf_confirm(self, button):
        button.click()
        self.wait(period=1)
        self.vdsm_config_dialog_ok.click()
        self.wait(period=2)
    
    # function_9: check vdsm configurate file on remote host
    def _check_vdsm_conf_host(self):
        remote_path = "/etc/vdsm/vdsm.conf"
        fd = StringIO()
        get(remote_path, fd)
        content = fd.getvalue()
        assert not re.search(str_input, content), "Edit & Save vdsm.conf failed"
class HePage(PageObject):
    """
    Hosted engine page
    """
    ok_icons = MultiPageElement(class_name="pficon-ok")
    vcenters = MultiPageElement(class_name="vcenter")
    btns = MultiPageElement(class_name="btn-default")
    panel_titles = MultiPageElement(class_name="panel-title")
    panel_bodys = MultiPageElement(class_name="panel-body")

    vm_state_txts = MultiPageElement(
        xpath=".//*[@class='list-view-pf-additional-info']/div/div")
    list_group_item_txts = MultiPageElement(class_name="list-group-item-text")

    global_maintenance_div = PageElement(xpath=".//*[@class='panel-body']/div")

    # frame name
    frame_right_name = "cockpit1:localhost/ovirt-dashboard"

    def __init__(self, *args, **kwargs):
        super(HePage, self).__init__(*args, **kwargs)
        self.get("/ovirt-dashboard#/he")
        self.wait(10)

    def check_three_buttons(self):
        """
        Purpose:
            Chech three "Maintenance" buttons exist
        """
        assert len(list(self.btns)) == 2, "Maintenance buttons not exist"

    def check_engine_status(self):
        """
        Purpose:
            Check the engine status
        """
        with self.switch_to_frame(self.frame_right_name):
            ok_icons = list(self.ok_icons)
            assert len(ok_icons) == 2, "Hosted engine status not up"

            he_status_txt = list(self.vcenters)[0]
            assert he_status_txt.text.strip() == "Hosted Engine is up!",    \
                "Hosted engine status not up"

    def check_vm_status(self):
        """
        Purpose:
            Check the host status
        """
        with self.switch_to_frame(self.frame_right_name):
            assert re.search('up', list(self.vm_state_txts)[0].text),   \
                "The VM is not up"

    def check_he_running_on_host(self, host_ip):
        """
        Purpose:
            Check the hosted engine is running on local host
        """
        cmd = "hostname"
        hostname = run(cmd)
        with self.switch_to_frame(self.frame_right_name):
            he_running_on_txt = list(self.vcenters)[1]
            print he_running_on_txt.text
            print hostname
            assert re.search(hostname, he_running_on_txt.text),     \
                "Hosted engine running on host not correct"

    def put_host_to_local_maintenance(self):
        """
        Purpose:
            Put the host to local maintenance
        """
        with self.switch_to_frame(self.frame_right_name):
            put_host_local_maintenace_btn = list(self.btns)[0]
            put_host_local_maintenace_btn.click()
            self.wait(60)

    def check_host_in_local_maintenance(self):
        """
        Purpose:
            Check the host is in local maintenance
        """
        with self.switch_to_frame(self.frame_right_name):
            host_agent_maintenance_txt = list(self.list_group_item_txts)[0].text
            host_maintenance_txt = host_agent_maintenance_txt.split()[-1]
            assert host_maintenance_txt == "true",  \
                "Host is not in local maintenance"

    def check_host_not_in_local_maintenance(self):
        """
        Purpose:
            Check the host is not in local maintenance
        """
        with self.switch_to_frame(self.frame_right_name):
            host_agent_maintenance_txt = list(self.list_group_item_txts)[0].text
            host_maintenance_txt = host_agent_maintenance_txt.split()[-1]
            assert host_maintenance_txt == "false",     \
                "Host is in local maintenance"

    def remove_host_from_local_maintenance(self):
        """
        Purpose:
            Remove the host from local maintenance
        """
        with self.switch_to_frame(self.frame_right_name):
            remove_host_local_maintenace_btn = list(self.btns)[1]
            remove_host_local_maintenace_btn.click()
            self.wait(60)

    def put_cluster_to_global_maintenance(self):
        """
        Purpose:
            Put the cluster to global maintenance
        """
        with self.switch_to_frame(self.frame_right_name):
            put_host_local_maintenace_btn = list(self.btns)[2]
            put_host_local_maintenace_btn.click()
            self.wait(10)

    def check_cluster_in_global_maintenance(self):
        """
        Purpose:
            Check whether the cluster is in global maintenance
        """
        with self.switch_to_frame(self.frame_right_name):
            if not self.global_maintenance_div.find(True):
                assert 0, "The cluster is not in global maintenance"

    def check_vm_migrated(self):
        """
            Suppose there are only two hosts,
            check the HE vm already migrate to another host
        """
        with self.switch_to_frame(self.frame_right_name):
            host_agent_maintenance_txt = list(self.list_group_item_txts)[1].text
            host_maintenance_txt = host_agent_maintenance_txt.split()[-1]
            assert host_maintenance_txt == "true",  \
                "The HE vm did not migrated to another host"
Esempio n. 22
0
class LoginPage(PageObject):
    """Login page action method come here"""

    brand_log = PageElement(id_="brand")

    username_input = PageElement(id_="login-user-input")
    password_input = PageElement(id_="login-password-input")
    login_btn = PageElement(id_="login-button")
    login_error_message = PageElement(id_="login-error-message")

    # Other options
    other_option = PageElement(id_="option-caret")
    server_input = PageElement(id_="server-field")

    # After click the Login button
    md5_input = PageElement(id_="conversation-input")

    def __init__(self, *args, **kwargs):
        super(LoginPage, self).__init__(*args, **kwargs)
        self.get("/")
        self.wait_until_element_visible(self.username_input)

    def basic_check_elements_exists(self):
        assert self.username_input, "input username not exist"
        assert self.password_input, "input password not exist"
        assert self.login_btn, "login btn not exist"
        self.wait()

    def login_with_credential(self, username, password):
        self.username_input.clear()
        self.wait(0.5)
        self.username_input.send_keys(username)
        self.wait(0.5)

        self.password_input.clear()
        self.wait(0.5)
        self.password_input.send_keys(password)
        self.wait(0.5)

        self.login_btn.click()
        self.wait()

    def login_with_incorrect_credential(self):
        self.username_input.send_keys("cockpit")
        self.password_input.send_keys("none")
        self.login_btn.click()
        self.wait(5)

        assert re.search(
            "Wrong user name or password",
            self.login_error_message.text),    \
            "No error message prompt with incorrect credential login"

    def check_allow_unknown_default(self):
        """
        Purpose:
            Login into remote machine with "allowUnknow" is default in cockpit
        """
        with settings(warn_only=True):
            cmd = "rm -f /etc/cockpit/cockpit.conf"
            run(cmd)
            cmd = "service cockpit restart"
            run(cmd)
        self.username_input.send_keys("root")
        self.password_input.send_keys("redhat")

        self.other_option.click()
        self.server_input.send_keys("10.66.8.173")
        self.login_btn.click()
        self.wait(5)

        assert re.search(
            "Refusing to connect. Host is unknown",
            self.login_error_message.text),     \
            "Wrong error message [%s] prompt with allownUnknow default" % \
            self.login_error_message.text

    def check_allow_unknown_true(self, another_ip, another_user,
                                 another_password):
        """
        Purpose:
            Login into remote machine with "allowUnknow" is true in cockpit
        """
        # Modify "allowUnknown=True" in /etc/cockpit/cockpit.conf
        source = '''
[SSH-Login]
host=%s
allowUnknown=true
'''
        with settings(warn_only=True):
            cmd = "rm -f /etc/cockpit/cockpit.conf"
            run(cmd)
            cmd = "echo '%s' >> /etc/cockpit/cockpit.conf" % (source %
                                                              another_ip)
            run(cmd)
            cmd = "service cockpit restart"
            run(cmd)
        self.username_input.send_keys(another_user)
        self.password_input.send_keys(another_password)

        self.other_option.click()
        self.server_input.send_keys(another_ip)
        self.login_btn.click()
        self.wait(5)
        self.login_btn.click()

    def check_allow_unknown_true_wrong_account(self, another_ip):
        """
        Purpose:
            Login into remote machine with "allowUnknow" is true in cockpit
        """
        # Modify "allowUnknown=True" in /etc/cockpit/cockpit.conf
        source = '''
[SSH-Login]
host=%s
allowUnknown=true
''' % another_ip
        with settings(warn_only=True):
            cmd = "rm -f /etc/cockpit/cockpit.conf"
            run(cmd)
            cmd = "echo '%s' >> /etc/cockpit/cockpit.conf" % source
            run(cmd)
            cmd = "service cockpit restart"
            run(cmd)
        self.username_input.send_keys("cockpit")
        self.password_input.send_keys("none")

        self.other_option.click()
        self.server_input.send_keys(another_ip)
        self.login_btn.click()
        self.wait(5)

        assert re.search(
            "Wrong user name or password",
            self.login_error_message.text),     \
            "Wrong error message [%s] prompt with allownUnknow true with wrong account" % \
            self.login_error_message.text

    def check_allow_unknown_true_remote_closed(self, another_ip, another_user,
                                               another_password):
        """
        Purpose:
            Login remote closed host with "allowUnknow" is true in cockpit
        """
        # Modify "allowUnknown=True" in /etc/cockpit/cockpit.conf
        source = '''
[SSH-Login]
host=%s
allowUnknown=true
''' % another_ip
        with settings(warn_only=True):
            cmd = "rm -f /etc/cockpit/cockpit.conf"
            run(cmd)
            cmd = "echo '%s' >> /etc/cockpit/cockpit.conf" % source
            run(cmd)
            cmd = "service cockpit restart"
            run(cmd)
        self.username_input.send_keys(another_user)
        self.password_input.send_keys(another_password)

        self.other_option.click()
        self.server_input.send_keys(another_ip)
        self.login_btn.click()
        self.wait(5)

        assert re.search(
            "Authentication Failed, Server closed connection",
            self.login_error_message.text),     \
            "Wrong error message [%s] prompt with allownUnknow true with remote closed" % \
            self.login_error_message.text

    def check_allow_unknown_true_wrong_address(self):
        """
        Purpose:
            Login remote host with wrong address in cockpit
        """
        # Modify "allowUnknown=True" in /etc/cockpit/cockpit.conf
        source = '''
[SSH-Login]
host=10.8.8.8
allowUnknown=true
'''
        with settings(warn_only=True):
            cmd = "rm -f /etc/cockpit/cockpit.conf"
            run(cmd)
            cmd = "echo '%s' >> /etc/cockpit/cockpit.conf" % source
            run(cmd)
            cmd = "service cockpit restart"
            run(cmd)
        self.username_input.send_keys("root")
        self.password_input.send_keys("redhat")

        self.other_option.click()
        self.server_input.send_keys("10.8.8.8")
        self.login_btn.click()
        self.wait(30)

        assert re.search(
            "Unable to connect to that address",
            self.login_error_message.text),     \
            "Wrong error message [%s] prompt with allownUnknow true with wrong address" % \
            self.login_error_message.text

    def check_allow_unknown_true_empty_username(self, another_ip, another_user,
                                                another_password):
        """
        Purpose:
            Login remote host with empty username in cockpit
        """
        # Modify "allowUnknown=True" in /etc/cockpit/cockpit.conf
        source = '''
[SSH-Login]
host=%s
allowUnknown=true
''' % another_ip
        with settings(warn_only=True):
            cmd = "rm -f /etc/cockpit/cockpit.conf"
            run(cmd)
            cmd = "echo '%s' >> /etc/cockpit/cockpit.conf" % source
            run(cmd)
            cmd = "service cockpit restart"
            run(cmd)

        self.password_input.send_keys(another_password)

        self.other_option.click()
        self.server_input.send_keys(another_ip)
        self.login_btn.click()
        self.wait(5)

        assert re.search(
            "User name cannot be empty",
            self.login_error_message.text),     \
            "Wrong error message [%s] prompt with allownUnknow true with empty user" % \
            self.login_error_message.text