def test_remove_networks_delete_failed(self, mock_logger_debug,
                                        mock_logger_error,
                                        mock_remove_ports,
                                        mock_remove_routers):
     with mock.patch('functest.utils.openstack_clean.os_utils'
                     '.get_network_list',
                     return_value=self.test_dict_list), \
             mock.patch('functest.utils.openstack_clean.os_utils'
                        '.delete_neutron_net', return_value=False), \
             mock.patch('functest.utils.openstack_clean.os_utils'
                        '.get_port_list', return_value=self.ports), \
             mock.patch('functest.utils.openstack_clean.os_utils'
                        '.get_router_list', return_value=self.routers):
         openstack_clean.remove_networks(self.client, self.remove_list,
                                         self.remove_list)
         mock_logger_debug.assert_any_call("Removing Neutron objects")
         mock_logger_error.assert_any_call(
             test_utils.RegexMatch("There has been a"
                                   " problem removing"
                                   " the network \s*\S+"
                                   "..."))
         mock_logger_debug.assert_any_call(
             test_utils.RegexMatch("Removing network "
                                   "\s*\S+ ..."))
         mock_remove_ports.assert_called_once_with(self.client, self.ports,
                                                   ['id1', 'id2'])
         mock_remove_routers.assert_called_once_with(
             self.client, self.routers, self.remove_list)
Пример #2
0
    def _test_show_missing_env_var(self, var, *args):
        if var == 'INSTALLER_TYPE':
            CONST.INSTALLER_TYPE = None
            reg_string = "|  INSTALLER: Unknown, \S+\s*|"
        elif var == 'INSTALLER_IP':
            CONST.INSTALLER_IP = None
            reg_string = "|  INSTALLER: \S+, Unknown\s*|"
        elif var == 'SCENARIO':
            CONST.DEPLOY_SCENARIO = None
            reg_string = "|   SCENARIO: Unknown\s*|"
        elif var == 'NODE':
            CONST.NODE_NAME = None
            reg_string = "|        POD: Unknown\s*|"
        elif var == 'BUILD_TAG':
            CONST.BUILD_TAG = None
            reg_string = "|  BUILD TAG: None|"
        elif var == 'DEBUG':
            CONST.CI_DEBUG = None
            reg_string = "| DEBUG FLAG: false\s*|"
        elif var == 'STATUS':
            reg_string = "|     STATUS: not ready\s*|"

        with mock.patch('functest.cli.commands.cli_env.click.echo') \
                as mock_click_echo:
            self.cli_environ.show()
            mock_click_echo.assert_called_with(
                test_utils.RegexMatch(reg_string))
 def test_remove_tenants_delete_failed(self, mock_logger_debug,
                                       mock_logger_error):
     with mock.patch('functest.utils.openstack_clean.os_utils'
                     '.get_tenants', return_value=self.test_list), \
             mock.patch('functest.utils.openstack_clean.os_utils'
                        '.delete_tenant', return_value=False):
         openstack_clean.remove_tenants(self.client, self.remove_list)
         mock_logger_debug.assert_any_call("Removing Tenants...")
         mock_logger_error.assert_any_call(
             test_utils.RegexMatch("There has been a "
                                   "problem removing "
                                   "the tenant \s*\S+"
                                   "..."))
         mock_logger_debug.assert_any_call(
             test_utils.RegexMatch(" Removing "
                                   "\s*\S+..."))
    def test_remove_networks_delete_success(self, mock_logger_debug,
                                            mock_remove_ports,
                                            mock_remove_routers):

        with mock.patch('functest.utils.openstack_clean.os_utils'
                        '.get_network_list',
                        return_value=self.test_dict_list), \
                mock.patch('functest.utils.openstack_clean.os_utils'
                           '.delete_neutron_net', return_value=True), \
                mock.patch('functest.utils.openstack_clean.os_utils'
                           '.get_port_list', return_value=self.ports), \
                mock.patch('functest.utils.openstack_clean.os_utils'
                           '.get_router_list', return_value=self.routers):
            openstack_clean.remove_networks(self.client, self.remove_list,
                                            self.remove_list)
            mock_logger_debug.assert_any_call("Removing Neutron objects")
            mock_logger_debug.assert_any_call("   > this network will be "
                                              "deleted.")
            mock_logger_debug.assert_any_call("  > Done!")
            mock_logger_debug.assert_any_call(
                test_utils.RegexMatch("Removing network "
                                      "\s*\S+ ..."))
            mock_remove_ports.assert_called_once_with(self.client, self.ports,
                                                      ['id1', 'id2'])
            mock_remove_routers.assert_called_once_with(
                self.client, self.routers, self.remove_list)
 def test_remove_images_delete_failed(self, mock_logger_debug,
                                      mock_logger_error):
     with mock.patch('functest.utils.openstack_clean.os_utils'
                     '.get_images', return_value=self.test_list), \
             mock.patch('functest.utils.openstack_clean.os_utils'
                        '.delete_glance_image', return_value=False):
         openstack_clean.remove_images(self.client, self.remove_list)
         mock_logger_debug.assert_any_call("Removing Glance images...")
         mock_logger_error.assert_any_call(
             test_utils.RegexMatch("There has been a "
                                   "problem removing the"
                                   "image \s*\S+..."))
         mock_logger_debug.assert_any_call(
             test_utils.RegexMatch("Removing image "
                                   "\s*\S+,"
                                   " ID=\s*\S+ ..."))
 def test_remove_routers_failed(self, mock_logger_debug, mock_logger_error):
     with mock.patch(
             'functest.utils.openstack_clean.os_utils'
             '.delete_neutron_router',
             return_value=False):
         openstack_clean.remove_routers(self.client, self.test_dict_list,
                                        self.remove_list)
         mock_logger_debug.assert_any_call("Router is not connected"
                                           " to anything."
                                           "Ready to remove...")
         mock_logger_debug.assert_any_call(
             test_utils.RegexMatch("Removing router "
                                   "\s*\S+(\s*\S+) ..."))
         mock_logger_error.assert_any_call(
             test_utils.RegexMatch("There has been "
                                   "a problem"
                                   " removing the "
                                   "router \s*\S+("
                                   "\s*\S+)..."))
 def test_remove_tenants_delete_success(self, mock_logger_debug):
     with mock.patch('functest.utils.openstack_clean.os_utils'
                     '.get_tenants', return_value=self.test_list), \
             mock.patch('functest.utils.openstack_clean.os_utils'
                        '.delete_tenant', return_value=True):
         openstack_clean.remove_tenants(self.client, self.remove_list)
         mock_logger_debug.assert_any_call("Removing Tenants...")
         mock_logger_debug.assert_any_call("  > Done!")
         mock_logger_debug.assert_any_call(
             test_utils.RegexMatch(" Removing "
                                   "\s*\S+..."))
 def test_force_remove_port(self, mock_logger_debug, mock_logger_error,
                            mock_update_neutron_port):
     with mock.patch(
             'functest.utils.openstack_clean.os_utils'
             '.delete_neutron_port',
             return_value=True):
         openstack_clean.force_remove_port(self.client, 'id')
         mock_logger_debug.assert_any_call("  > Done!")
         mock_logger_debug.assert_any_call(
             test_utils.RegexMatch("Clearing device_"
                                   "owner for port "
                                   "\s*\S+ ..."))
 def test_remove_floatingips_delete_success(self, mock_logger_debug):
     with mock.patch('functest.utils.openstack_clean.os_utils'
                     '.get_floating_ips',
                     return_value=self.floatingips_list), \
             mock.patch('functest.utils.openstack_clean.os_utils'
                        '.delete_floating_ip', return_value=True):
         openstack_clean.remove_floatingips(self.client, self.remove_list)
         mock_logger_debug.assert_any_call("Removing floating IPs...")
         mock_logger_debug.assert_any_call("  > Done!")
         mock_logger_debug.assert_any_call(
             test_utils.RegexMatch("Removing floating "
                                   "IP \s*\S+ ..."))
 def test_remove_images_delete_success(self, mock_logger_debug):
     with mock.patch('functest.utils.openstack_clean.os_utils'
                     '.get_images', return_value=self.test_list), \
             mock.patch('functest.utils.openstack_clean.os_utils'
                        '.delete_glance_image', return_value=True):
         openstack_clean.remove_images(self.client, self.remove_list)
         mock_logger_debug.assert_any_call("Removing Glance images...")
         mock_logger_debug.assert_any_call("  > Done!")
         mock_logger_debug.assert_any_call(
             test_utils.RegexMatch("Removing image "
                                   "\s*\S+,"
                                   " ID=\s*\S+ ..."))
 def test_remove_security_groups_delete_success(self, mock_logger_debug):
     with mock.patch('functest.utils.openstack_clean.os_utils'
                     '.get_security_groups',
                     return_value=self.test_dict_list), \
             mock.patch('functest.utils.openstack_clean.os_utils'
                        '.delete_security_group', return_value=True):
         openstack_clean.remove_security_groups(self.client,
                                                self.remove_list)
         mock_logger_debug.assert_any_call("Removing Security groups...")
         mock_logger_debug.assert_any_call("  > Done!")
         mock_logger_debug.assert_any_call(
             test_utils.RegexMatch(" Removing \s*\S+"
                                   "..."))
 def test_remove_instances_other_delete_success(self, mock_logger_debug):
     with mock.patch('functest.utils.openstack_clean.os_utils'
                     '.get_instances', return_value=self.other_list), \
             mock.patch('functest.utils.openstack_clean.os_utils'
                        '.delete_instance', return_value=True):
         openstack_clean.remove_instances(self.client, self.remove_list)
         mock_logger_debug.assert_any_call("Removing Nova instances...")
         mock_logger_debug.assert_any_call("  > Request sent.")
         mock_logger_debug.assert_any_call(
             test_utils.RegexMatch("Removing"
                                   " instance"
                                   " '\s*\S+'"
                                   " ..."))
 def test_remove_routers_missing_routers(self, mock_logger_debug):
     with mock.patch(
             'functest.utils.openstack_clean.os_utils'
             '.delete_neutron_router',
             return_value=True):
         openstack_clean.remove_routers(self.client, self.test_dict_list,
                                        self.remove_list)
         mock_logger_debug.assert_any_call("Router is not connected"
                                           " to anything."
                                           "Ready to remove...")
         mock_logger_debug.assert_any_call("  > Done!")
         mock_logger_debug.assert_any_call(
             test_utils.RegexMatch("Removing router "
                                   "\s*\S+(\s*\S+) ..."))
 def test_remove_missing_external_gateway(self, mock_logger_debug,
                                          mock_logger_error):
     with mock.patch('functest.utils.openstack_clean.os_utils'
                     '.delete_neutron_router',
                     return_value=False), \
             mock.patch('functest.utils.openstack_clean.os_utils'
                        '.remove_gateway_router',
                        return_value=False):
         self.test_dict_list[0]['external_gateway_info'] = mock.Mock()
         openstack_clean.remove_routers(self.client, self.test_dict_list,
                                        self.remove_list)
         mock_logger_debug.assert_any_call("Router has gateway to external"
                                           " network.Removing link...")
         mock_logger_error.assert_any_call("There has been a problem "
                                           "removing the gateway...")
         mock_logger_debug.assert_any_call(
             test_utils.RegexMatch("Removing router "
                                   "\s*\S+(\s*\S+) ..."))
         mock_logger_error.assert_any_call(
             test_utils.RegexMatch("There has been "
                                   "a problem"
                                   " removing the "
                                   "router \s*\S+("
                                   "\s*\S+)..."))
 def test_force_remove_port_failed(self, mock_logger_debug,
                                   mock_logger_error,
                                   mock_update_neutron_port):
     with mock.patch(
             'functest.utils.openstack_clean.os_utils'
             '.delete_neutron_port',
             return_value=False):
         openstack_clean.force_remove_port(self.client, 'id')
         mock_logger_error.assert_any_call("There has been a "
                                           "problem removing "
                                           "the port id...")
         mock_logger_debug.assert_any_call(
             test_utils.RegexMatch("Clearing device_"
                                   "owner for port "
                                   "\s*\S+ ..."))
 def test_push_results_to_db_request_post_failed(self):
     dic = self._get_env_dict(None)
     CONST.__setattr__('results_test_db_url', self.db_url)
     with mock.patch.dict(os.environ,
                          dic,
                          clear=True), \
             mock.patch('functest.utils.functest_utils.logger.error') \
             as mock_logger_error, \
             mock.patch('functest.utils.functest_utils.requests.post',
                        side_effect=requests.RequestException):
         self.assertFalse(
             functest_utils.push_results_to_db(self.project, self.case_name,
                                               self.start_date,
                                               self.stop_date, self.result,
                                               self.details))
         mock_logger_error.assert_called_once_with(
             test_utils.RegexMatch("Pushing "
                                   "Result to"
                                   " DB"
                                   "(\S+\s*) "
                                   "failed:"))