Example #1
0
 def setUp(self):
     test_config = TestConfig()
     self.data_path = test_config.get_data_path()
     config = Configuration(os.path.join(self.data_path,'build.ini'))
     db_name = config.get('mongodb1','db_name')
     host = config.get('mongodb1','host')
     config = MongoDBConfig(db_name, host)
     self.db = MongoDB(config)
Example #2
0
    def test_hosts_setup(self):
        """test multi-host setup"""
        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

        yml_path = self.get_yml_path()
        hostnames = test_config.get_hostnames()
        for hostname in hostnames:
            self.run_cli_cmd('host add %s' % hostname)

        # test all hosts, success path
        use_uname = False
        yml_dict = {}
        for hostname in hostnames:
            yml_dict[hostname] = {}
            password = test_config.get_password(hostname)
            if use_uname:
                yml_dict[hostname]['uname'] = 'root'
            use_uname = not use_uname
            yml_dict[hostname]['password'] = password
        self.write_yml(yml_dict)
        msg = self.run_cli_cmd('host setup --file %s' % yml_path)
        self.log.info(msg)

        # failure paths

        # no hostname and no file spec
        msg = self.run_cli_cmd('host setup', True)
        self.assertIn('ERROR', msg, 'No command params did not error')

        # hostname and file spec both present
        msg = self.run_cli_cmd('host setup -f zzzzz hostname', True)
        self.assertIn('ERROR', msg, '2 params did not error')

        # non-existent file
        msg = self.run_cli_cmd('host setup -f !INVALID_FILE_PATH!', True)
        self.assertIn('ERROR', msg, 'Non-existent yml file did not error')

        # empty file
        self.write_yml({})
        msg = self.run_cli_cmd('host setup -f %s' % yml_path, True)
        self.assertIn('ERROR', msg, 'Empty yml file did not error')

        # non-existent host
        self.write_yml({'NOT_HOSTNAME': {'password': '******'}})
        msg = self.run_cli_cmd('host setup -f %s' % yml_path, True)
        self.assertIn('ERROR', msg, 'non-existent host did not error')

        # no password for host
        self.write_yml({hostnames[0]: {'uname': 'name'}})
        msg = self.run_cli_cmd('host setup -f %s' % yml_path, True)
        self.assertIn('ERROR', msg, 'no password for host did not error')
Example #3
0
    def test_hosts_setup(self):
        """test multi-host setup"""
        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

        yml_path = self.get_yml_path()
        hostnames = test_config.get_hostnames()
        for hostname in hostnames:
            self.run_cli_cmd('host add %s' % hostname)

        # test all hosts, success path
        use_uname = False
        yml_dict = {}
        for hostname in hostnames:
            yml_dict[hostname] = {}
            password = test_config.get_password(hostname)
            if use_uname:
                yml_dict[hostname]['uname'] = 'root'
            use_uname = not use_uname
            yml_dict[hostname]['password'] = password
        self.write_yml(yml_dict)
        msg = self.run_cli_cmd('host setup --file %s' % yml_path)
        self.log.info(msg)

        # failure paths

        # no hostname and no file spec
        msg = self.run_cli_cmd('host setup', True)
        self.assertIn('ERROR', msg, 'No command params did not error')

        # hostname and file spec both present
        msg = self.run_cli_cmd('host setup -f zzzzz hostname', True)
        self.assertIn('ERROR', msg, '2 params did not error')

        # non-existent file
        msg = self.run_cli_cmd('host setup -f !INVALID_FILE_PATH!', True)
        self.assertIn('ERROR', msg, 'Non-existent yml file did not error')

        # empty file
        self.write_yml({})
        msg = self.run_cli_cmd('host setup -f %s' % yml_path, True)
        self.assertIn('ERROR', msg, 'Empty yml file did not error')

        # non-existent host
        self.write_yml({'NOT_HOSTNAME': {'password': '******'}})
        msg = self.run_cli_cmd('host setup -f %s' % yml_path, True)
        self.assertIn('ERROR', msg, 'non-existent host did not error')

        # no password for host
        self.write_yml({hostnames[0]: {'uname': 'name'}})
        msg = self.run_cli_cmd('host setup -f %s' % yml_path, True)
        self.assertIn('ERROR', msg, 'no password for host did not error')
Example #4
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 #5
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 #6
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 #7
0
 def setUp(self):
     test_config = TestConfig()
     self.data_path = test_config.get_data_path()
     self.output_path = test_config.get_output_path()
Example #8
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 #9
0
    def test_host_add_remove(self):
        hosts = TestConfig()

        msg = self.run_cli_cmd('host list -f json')
        self._check_cli_output(hosts, msg)

        host1 = 'host_test1'
        host2 = 'host_test2'

        group1 = 'control'

        hosts.add_host(host1)
        self.run_cli_cmd('host add %s' % host1)
        msg = self.run_cli_cmd('host list -f json')
        self._check_cli_output(hosts, msg)

        hosts.add_host(host2)
        self.run_cli_cmd('host add %s' % host2)
        msg = self.run_cli_cmd('host list -f json')
        self._check_cli_output(hosts, msg)

        hosts.remove_host(host2)
        self.run_cli_cmd('host remove %s' % host2)
        msg = self.run_cli_cmd('host list -f json')
        self._check_cli_output(hosts, msg)

        hosts.remove_host(host1)
        self.run_cli_cmd('host remove %s' % host1)
        msg = self.run_cli_cmd('host list -f json')
        self._check_cli_output(hosts, msg)

        # check groups in host list
        hosts.add_host(host1)
        hosts.add_group(host1, group1)
        self.run_cli_cmd('host add %s' % host1)
        self.run_cli_cmd('group addhost %s %s' % (group1, host1))
        msg = self.run_cli_cmd('host list -f json')
        self._check_cli_output(hosts, msg)

        hosts.remove_group(host1, group1)
        self.run_cli_cmd('group removehost %s %s' % (group1, host1))
        msg = self.run_cli_cmd('host list -f json')
        self._check_cli_output(hosts, msg)
Example #10
0
    def test_host_add_remove(self):
        hosts = TestConfig()

        msg = self.run_cli_cmd('host list -f json')
        self._check_cli_output(hosts, msg)

        host1 = 'host_test1'
        host2 = 'host_test2'

        group1 = 'control'

        hosts.add_host(host1)
        self.run_cli_cmd('host add %s' % host1)
        msg = self.run_cli_cmd('host list -f json')
        self._check_cli_output(hosts, msg)

        hosts.add_host(host2)
        self.run_cli_cmd('host add %s' % host2)
        msg = self.run_cli_cmd('host list -f json')
        self._check_cli_output(hosts, msg)

        hosts.remove_host(host2)
        self.run_cli_cmd('host remove %s' % host2)
        msg = self.run_cli_cmd('host list -f json')
        self._check_cli_output(hosts, msg)

        hosts.remove_host(host1)
        self.run_cli_cmd('host remove %s' % host1)
        msg = self.run_cli_cmd('host list -f json')
        self._check_cli_output(hosts, msg)

        # check groups in host list
        hosts.add_host(host1)
        hosts.add_group(host1, group1)
        self.run_cli_cmd('host add %s' % host1)
        self.run_cli_cmd('group addhost %s %s' % (group1, host1))
        msg = self.run_cli_cmd('host list -f json')
        self._check_cli_output(hosts, msg)

        hosts.remove_group(host1, group1)
        self.run_cli_cmd('group removehost %s %s' % (group1, host1))
        msg = self.run_cli_cmd('host list -f json')
        self._check_cli_output(hosts, msg)