Example #1
0
    def test_host_setup(self):
        test_config = TestConfig()
        test_config.load()

        if not test_config.get_hostnames():
            self.log.info('no hosts found in test_config.json file, ' +
                          'skipping test')
            return

        hostname = test_config.get_hostnames()[0]

        key_path = '/usr/share/kolla/.ssh/authorized_keys'
        test_config.run_remote_cmd(
            'cat /dev/null > %s' % key_path, hostname)

        pwd = test_config.get_password(hostname)

        self.run_cli_cmd('host add %s' % hostname)

        # check if host is not set-up
        timeout = time.time() + 75
        while time.time <= timeout:
            msg = self.run_cli_cmd('host check %s' % hostname, True)
            if 'ERROR:' not in msg:
                self.log.info('waiting for ansible ssh session to timeout')
                time.sleep(10)
            break

        self.assertLessEqual(time.time(), timeout,
                             'check succeeded after key removal' +
                             '(%s)' % hostname)

        # setup the host
        self.run_cli_cmd('host setup %s --insecure %s'
                         % (hostname, pwd))
        msg = self.run_cli_cmd('host check %s' % hostname, True)
        self.assertNotIn('ERROR:', msg, 'Check after setup failed on ' +
                         'host: (%s)' % hostname)
Example #2
0
    def test_host_setup(self):
        test_config = TestConfig()
        test_config.load()

        if not test_config.get_hostnames():
            self.log.info('no hosts found in test_config.json file, ' +
                          'skipping test')
            return

        hostname = test_config.get_hostnames()[0]

        key_path = '/usr/share/kolla/.ssh/authorized_keys'
        test_config.run_remote_cmd('cat /dev/null > %s' % key_path, hostname)

        pwd = test_config.get_password(hostname)

        self.run_cli_cmd('host add %s' % hostname)

        # check if host is not set-up
        timeout = time.time() + 75
        while time.time <= timeout:
            msg = self.run_cli_cmd('host check %s' % hostname, True)
            if 'ERROR:' not in msg:
                self.log.info('waiting for ansible ssh session to timeout')
                time.sleep(10)
            break

        self.assertLessEqual(
            time.time(), timeout,
            'check succeeded after key removal' + '(%s)' % hostname)

        # setup the host
        self.run_cli_cmd('host setup %s --insecure %s' % (hostname, pwd))
        msg = self.run_cli_cmd('host check %s' % hostname, True)
        self.assertNotIn(
            'ERROR:', msg,
            'Check after setup failed on ' + 'host: (%s)' % hostname)
Example #3
0
    def test_destroy(self):
        test_config = TestConfig()
        test_config.load()

        # add host to inventory
        hostnames = test_config.get_hostnames()
        if hostnames:
            hostname = test_config.get_hostnames()[0]
            is_physical_host = True
            pwd = test_config.get_password(hostname)
        else:
            # No physical hosts in config, use a non-existent host.
            # This will generate expected exceptions in all host access
            # commands.
            hostname = 'test_deploy_host1'
            is_physical_host = False
            pwd = 'test_pwd'

        self.run_cli_cmd('host add %s' % hostname)

        try:
            self.run_cli_cmd('host setup %s --insecure %s'
                             % (hostname, pwd))
        except Exception as e:
            self.assertFalse(is_physical_host, 'host setup exception: %s' % e)
            self.assertIn(UNKNOWN_HOST, '%s' % e,
                          'Unexpected exception in host setup: %s' % e)

        # add host to all deploy groups
        for group in inventory.DEPLOY_GROUPS:
            self.run_cli_cmd('group addhost %s %s' % (group, hostname))

        # destroy services, initialize server
        try:
            self.run_cli_cmd('host destroy %s' % hostname)
        except Exception as e:
            self.assertFalse(is_physical_host, '1st destroy exception: %s' % e)
            self.assertIn(UNKNOWN_HOST, '%s' % e,
                          'Unexpected exception in 1st destroy: %s' % e)

        # disable most services so the test is quicker
        for disabled_service in DISABLED_SERVICES:
            self.run_cli_cmd('property set enable_%s no' % disabled_service)

        for enabled_service in ENABLED_SERVICES:
            self.run_cli_cmd('property set enable_%s yes' % enabled_service)

        predeploy_cmds = test_config.get_predeploy_cmds()
        for predeploy_cmd in predeploy_cmds:
            self.run_cli_cmd('%s' % predeploy_cmd)

        # deploy limited services openstack
        try:
            msg = self.run_cli_cmd('deploy -v')
            self.log.info(msg)
        except Exception as e:
            self.assertFalse(is_physical_host, 'deploy exception: %s' % e)
            self.assertIn(UNKNOWN_HOST, '%s' % e,
                          'Unexpected exception in deploy: %s' % e)

        if is_physical_host:
            docker_ps = test_config.run_remote_cmd('docker ps', hostname)
            docker_ps = docker_ps.replace('\r', '\n')
            for disabled_service in DISABLED_SERVICES:
                self.assertNotIn(disabled_service, docker_ps,
                                 'disabled service: %s ' % disabled_service +
                                 'is running on host: %s ' % hostname +
                                 'after deploy.')

            for enabled_service in ENABLED_SERVICES:
                self.assertIn(enabled_service, docker_ps,
                              'enabled service: %s ' % enabled_service +
                              'is not running on host: %s ' % hostname +
                              'after deploy.')

        # destroy services (via --stop flag)
        try:
            self.run_cli_cmd('host destroy %s --stop' % hostname)
        except Exception as e:
            self.assertFalse(is_physical_host, '2nd destroy exception: %s' % e)
            self.assertIn(UNKNOWN_HOST, '%s' % e,
                          'Unexpected exception in 2nd destroy: %s' % e)

        if is_physical_host:
            docker_ps = test_config.run_remote_cmd('docker ps', hostname)
            for disabled_service in DISABLED_SERVICES:
                self.assertNotIn(disabled_service, docker_ps,
                                 'disabled service: %s ' % disabled_service +
                                 'is running on host: %s ' % hostname +
                                 'after destroy.')

            for enabled_service in ENABLED_SERVICES:
                self.assertNotIn(enabled_service, docker_ps,
                                 'enabled service: %s ' % enabled_service +
                                 'is still running on host: %s ' % hostname +
                                 'after destroy.')
Example #4
0
    def test_destroy(self):
        test_config = TestConfig()
        test_config.load()

        # add host to inventory
        hostnames = test_config.get_hostnames()
        if hostnames:
            hostname = test_config.get_hostnames()[0]
            is_physical_host = True
            pwd = test_config.get_password(hostname)
        else:
            # No physical hosts in config, use a non-existent host.
            # This will generate expected exceptions in all host access
            # commands.
            hostname = "test_deploy_host1"
            is_physical_host = False
            pwd = "test_pwd"

        self.run_cli_cmd("host add %s" % hostname)

        try:
            self.run_cli_cmd("host setup %s --insecure %s" % (hostname, pwd))
        except Exception as e:
            self.assertFalse(is_physical_host, "host setup exception: %s" % e)
            self.assertIn(UNKNOWN_HOST, "%s" % e, "Unexpected exception in host setup: %s" % e)

        # add host to all deploy groups
        for group in inventory.DEPLOY_GROUPS:
            self.run_cli_cmd("group addhost %s %s" % (group, hostname))

        # destroy services, initialize server
        try:
            self.run_cli_cmd("host destroy %s" % hostname)
        except Exception as e:
            self.assertFalse(is_physical_host, "1st destroy exception: %s" % e)
            self.assertIn(UNKNOWN_HOST, "%s" % e, "Unexpected exception in 1st destroy: %s" % e)

        # disable most services so the test is quicker
        for disabled_service in DISABLED_SERVICES:
            self.run_cli_cmd("property set enable_%s no" % disabled_service)

        for enabled_service in ENABLED_SERVICES:
            self.run_cli_cmd("property set enable_%s yes" % enabled_service)

        predeploy_cmds = test_config.get_predeploy_cmds()
        for predeploy_cmd in predeploy_cmds:
            self.run_cli_cmd("%s" % predeploy_cmd)

        # deploy limited services openstack
        try:
            msg = self.run_cli_cmd("deploy -v")
            self.log.info(msg)
        except Exception as e:
            self.assertFalse(is_physical_host, "deploy exception: %s" % e)
            self.assertIn(UNKNOWN_HOST, "%s" % e, "Unexpected exception in deploy: %s" % e)

        if is_physical_host:
            docker_ps = test_config.run_remote_cmd("docker ps", hostname)
            docker_ps = docker_ps.replace("\r", "\n")
            for disabled_service in DISABLED_SERVICES:
                self.assertNotIn(
                    disabled_service,
                    docker_ps,
                    "disabled service: %s " % disabled_service + "is running on host: %s " % hostname + "after deploy.",
                )

            for enabled_service in ENABLED_SERVICES:
                self.assertIn(
                    enabled_service,
                    docker_ps,
                    "enabled service: %s " % enabled_service
                    + "is not running on host: %s " % hostname
                    + "after deploy.",
                )

        # destroy services (via --stop flag)
        try:
            self.run_cli_cmd("host destroy %s --stop" % hostname)
        except Exception as e:
            self.assertFalse(is_physical_host, "2nd destroy exception: %s" % e)
            self.assertIn(UNKNOWN_HOST, "%s" % e, "Unexpected exception in 2nd destroy: %s" % e)

        if is_physical_host:
            docker_ps = test_config.run_remote_cmd("docker ps", hostname)
            for disabled_service in DISABLED_SERVICES:
                self.assertNotIn(
                    disabled_service,
                    docker_ps,
                    "disabled service: %s " % disabled_service
                    + "is running on host: %s " % hostname
                    + "after destroy.",
                )

            for enabled_service in ENABLED_SERVICES:
                self.assertNotIn(
                    enabled_service,
                    docker_ps,
                    "enabled service: %s " % enabled_service
                    + "is still running on host: %s " % hostname
                    + "after destroy.",
                )