Beispiel #1
0
def _get_cmd_prefix():
    editor_path = os.path.join(utils.get_kollacli_home(), 'tools',
                               PWD_EDITOR_FILENAME)
    pwd_file_path = os.path.join(utils.get_kolla_etc(), PWDS_FILENAME)
    user = utils.get_admin_user()
    prefix = '/usr/bin/sudo -u %s %s -p %s ' % (user, editor_path,
                                                pwd_file_path)
    return prefix
Beispiel #2
0
    def test_password_set_clear(self):

        # This test should leave the passwords.yml file unchanged
        # after the test completes.
        pwds_path = os.path.join(get_kolla_etc(), 'passwords.yml')
        size_start = os.path.getsize(pwds_path)

        # test list
        msg = self.run_cli_cmd('password list')
        key = 'database_password'
        value = '-'
        ok = self._password_value_exists(key, value, msg)
        self.assertTrue(
            ok, 'list failed. Password (%s/%s) not in output: %s' %
            (key, value, msg))

        # test append
        key = 'TeStKeY'
        value = '-'
        self.run_cli_cmd('password set %s --insecure %s' % (key, value))
        msg = self.run_cli_cmd('password list')
        ok = self._password_value_exists(key, value, msg)
        self.assertTrue(
            ok, 'set new password failed. Password ' +
            '(%s/%s) not in output: %s' % (key, value, msg))

        # test modify existing
        key = 'TeStKeY'
        value = '-'
        self.run_cli_cmd('password set %s --insecure %s' % (key, value))
        msg = self.run_cli_cmd('password list')
        ok = self._password_value_exists(key, value, msg)
        self.assertTrue(
            ok, 'set modify password failed. Password ' +
            '(%s/%s) not in output: %s' % (key, value, msg))

        # test clear
        key = 'TeStKeY'
        value = '-'
        self.run_cli_cmd('password clear %s' % key)
        msg = self.run_cli_cmd('password list')
        ok = self._password_value_exists(key, value, msg)
        self.assertFalse(
            ok, 'clear password failed. Password ' +
            '(%s/%s) not in output: %s' % (key, value, msg))

        # check that passwords.yml file size didn't change
        size_end = os.path.getsize(pwds_path)
        self.assertEqual(
            size_start, size_end, 'passwords.yml size changed ' +
            'from %s to %s' % (size_start, size_end))
Beispiel #3
0
    def test_property_set_clear(self):
        # test list

        # This test should leave the globals.yml file unchanged
        # after the test completes.
        globals_path = os.path.join(get_kolla_etc(), 'globals.yml')
        size_start = os.path.getsize(globals_path)

        msg = self.run_cli_cmd('property list')
        key = 'kolla_base_distro'
        value = 'ol'
        ok = self._property_value_exists(key, value, msg)
        self.assertTrue(ok, 'property not in output: %s, %s' % (key, value))

        # test append
        key = 'TeStKeY'
        value = 'TeStVaLuE'
        self.run_cli_cmd('property set %s %s' % (key, value))
        msg = self.run_cli_cmd('property list')
        ok = self._property_value_exists(key, value, msg)
        self.assertTrue(
            ok, 'set failed property not in output: %s, %s' % (key, value))

        # test modify existing
        key = 'TeStKeY'
        value = 'TeStVaLuE2'
        self.run_cli_cmd('property set %s %s' % (key, value))
        msg = self.run_cli_cmd('property list')
        ok = self._property_value_exists(key, value, msg)
        self.assertTrue(
            ok, 'set failed property not in output: %s, %s' % (key, value))

        # test clear
        key = 'TeStKeY'
        value = 'TeStVaLuE2'
        self.run_cli_cmd('property clear %s' % key)
        msg = self.run_cli_cmd('property list')
        ok = self._property_value_exists(key, value, msg)
        self.assertFalse(
            ok, 'clear failed property in output: %s, %s' % (key, value))

        # check that globals.yml file size didn't change
        size_end = os.path.getsize(globals_path)
        self.assertEqual(
            size_start, size_end, 'globals.yml size changed ' +
            'from %s to %s' % (size_start, size_end))
Beispiel #4
0
 def _run_rules(self):
     # check that ring files are in /etc/kolla/config/swift if
     # swift is enabled
     expected_files = ['account.ring.gz',
                       'container.ring.gz',
                       'object.ring.gz']
     properties = AnsibleProperties()
     is_enabled = properties.get_property('enable_swift')
     if is_enabled == 'yes':
         path_pre = os.path.join(get_kolla_etc(), 'config', 'swift')
         for expected_file in expected_files:
             path = os.path.join(path_pre, expected_file)
             if not os.path.isfile(path):
                 msg = ('Deploy failed. ' +
                        'Swift is enabled but ring buffers have ' +
                        'not yet been set up. Please see the ' +
                        'documentation for swift configuration ' +
                        'instructions.')
                 raise CommandError(msg)
Beispiel #5
0
    def take_action(self, parsed_args):
        try:
            kolla_home = get_kolla_home()
            kolla_logs = get_kolla_log_dir()
            kolla_ansible = os.path.join(kolla_home, 'ansible')
            kolla_docs = os.path.join(kolla_home, 'docs')
            kolla_etc = get_kolla_etc()
            kolla_config = os.path.join(kolla_etc, 'config')
            kolla_globals = os.path.join(kolla_etc, 'globals.yml')
            kollacli_etc = get_kollacli_etc().rstrip('/')
            ketc = 'kolla/etc/'
            kshare = 'kolla/share/'
            fd, dump_path = tempfile.mkstemp(prefix='kollacli_dump_',
                                             suffix='.tgz')
            os.close(fd)  # avoid fd leak
            with tarfile.open(dump_path, 'w:gz') as tar:
                # Can't blanket add kolla_home because the .ssh dir is
                # accessible by the kolla user only (not kolla group)
                tar.add(kolla_ansible,
                        arcname=kshare + os.path.basename(kolla_ansible))
                tar.add(kolla_docs,
                        arcname=kshare + os.path.basename(kolla_docs))

                # Can't blanket add kolla_etc because the passwords.yml
                # file is accessible by the kolla user only (not kolla group)
                tar.add(kolla_config,
                        arcname=ketc + os.path.basename(kolla_config))
                tar.add(kolla_globals,
                        arcname=ketc + os.path.basename(kolla_globals))
                tar.add(kollacli_etc,
                        arcname=ketc + os.path.basename(kollacli_etc))

                # add kolla log files
                if os.path.isdir(kolla_logs):
                    tar.add(kolla_logs)

                # add output of various commands
                self._add_cmd_info(tar)

            self.log.info('dump successful to %s' % dump_path)
        except Exception:
            raise Exception(traceback.format_exc())
 def _get_password_path(self):
     kolla_etc = get_kolla_etc()
     return (' -e @' + os.path.join(kolla_etc, 'passwords.yml '))
 def _get_globals_path(self):
     kolla_etc = get_kolla_etc()
     return (' -e @' + os.path.join(kolla_etc, 'globals.yml '))
Beispiel #8
0
    def __init__(self):
        """initialize ansible property information

        property information is pulled from the following files:
        KOLLA_ETC/globals.yml
        KOLLA_ETC/passwords.yml
        KOLLA_HOME/group_vars/all.yml
        KOLLA_HOME/ansible/roles/<service>/default/main.yml
        """
        kolla_etc = get_kolla_etc()
        kolla_home = get_kolla_home()

        self.allvars_path = ''
        self.globals_path = ''
        self.properties = []
        self.unique_properties = {}
        # this is so for any given property
        # we can look up the file it is in easily, to be used for the
        # property set command
        self.file_contents = {}

        try:
            start_dir = os.path.join(kolla_home, ANSIBLE_ROLES_PATH)
            services = next(os.walk(start_dir))[1]
            for service_name in services:
                file_name = os.path.join(start_dir, service_name,
                                         ANSIBLE_DEFAULTS_PATH)
                if os.path.isfile(file_name):
                    with open(file_name) as service_file:
                        service_contents = yaml.load(service_file)
                        self.file_contents[file_name] = service_contents
                        service_contents = self.filter_jinja2(service_contents)
                        prop_file_name = service_name + ':main.yml'
                        for key, value in service_contents.items():
                            ansible_property = AnsibleProperty(
                                key, value, prop_file_name)
                            self.properties.append(ansible_property)
                            self.unique_properties[key] = ansible_property
        except Exception as e:
            raise e

        try:
            self.allvars_path = os.path.join(kolla_home, ALLVARS_PATH)
            with open(self.allvars_path) as allvars_file:
                allvars_contents = yaml.load(allvars_file)
                self.file_contents[self.allvars_path] = allvars_contents
                allvars_contents = self.filter_jinja2(allvars_contents)
                for key, value in allvars_contents.items():
                    ansible_property = AnsibleProperty(key, value,
                                                       'group_vars/all.yml')
                    self.properties.append(ansible_property)
                    self.unique_properties[key] = ansible_property
        except Exception as e:
            raise e

        try:
            self.globals_path = os.path.join(kolla_etc, GLOBALS_FILENAME)
            globals_data = sync_read_file(self.globals_path)
            globals_contents = yaml.load(globals_data)
            self.file_contents[self.globals_path] = globals_contents
            globals_contents = self.filter_jinja2(globals_contents)
            for key, value in globals_contents.items():
                ansible_property = AnsibleProperty(key, value,
                                                   GLOBALS_FILENAME)
                self.properties.append(ansible_property)
                self.unique_properties[key] = ansible_property
        except Exception as e:
            raise e
Beispiel #9
0
 def _get_password_path(self):
     kolla_etc = get_kolla_etc()
     return (' -e @' + os.path.join(kolla_etc, 'passwords.yml '))
Beispiel #10
0
 def _get_globals_path(self):
     kolla_etc = get_kolla_etc()
     return (' -e @' + os.path.join(kolla_etc, 'globals.yml '))
def _get_cmd_prefix():
    editor_path = os.path.join(utils.get_kollacli_home(), "tools", PWD_EDITOR_FILENAME)
    pwd_file_path = os.path.join(utils.get_kolla_etc(), PWDS_FILENAME)
    user = utils.get_admin_user()
    prefix = "/usr/bin/sudo -u %s %s -p %s " % (user, editor_path, pwd_file_path)
    return prefix
    def __init__(self):
        """initialize ansible property information

        property information is pulled from the following files:
        KOLLA_ETC/globals.yml
        KOLLA_ETC/passwords.yml
        KOLLA_HOME/group_vars/all.yml
        KOLLA_HOME/ansible/roles/<service>/default/main.yml
        """
        kolla_etc = get_kolla_etc()
        kolla_home = get_kolla_home()

        self.allvars_path = ''
        self.globals_path = ''
        self.properties = []
        self.unique_properties = {}
        # this is so for any given property
        # we can look up the file it is in easily, to be used for the
        # property set command
        self.file_contents = {}

        try:
            start_dir = os.path.join(kolla_home, ANSIBLE_ROLES_PATH)
            services = next(os.walk(start_dir))[1]
            for service_name in services:
                file_name = os.path.join(start_dir, service_name,
                                         ANSIBLE_DEFAULTS_PATH)
                if os.path.isfile(file_name):
                    with open(file_name) as service_file:
                        service_contents = yaml.load(service_file)
                        self.file_contents[file_name] = service_contents
                        service_contents = self.filter_jinja2(service_contents)
                        prop_file_name = service_name + ':main.yml'
                        for key, value in service_contents.items():
                            ansible_property = AnsibleProperty(key, value,
                                                               prop_file_name)
                            self.properties.append(ansible_property)
                            self.unique_properties[key] = ansible_property
        except Exception as e:
            raise e

        try:
            self.allvars_path = os.path.join(kolla_home, ALLVARS_PATH)
            with open(self.allvars_path) as allvars_file:
                allvars_contents = yaml.load(allvars_file)
                self.file_contents[self.allvars_path] = allvars_contents
                allvars_contents = self.filter_jinja2(allvars_contents)
                for key, value in allvars_contents.items():
                    ansible_property = AnsibleProperty(key, value,
                                                       'group_vars/all.yml')
                    self.properties.append(ansible_property)
                    self.unique_properties[key] = ansible_property
        except Exception as e:
            raise e

        try:
            self.globals_path = os.path.join(kolla_etc, GLOBALS_FILENAME)
            globals_data = sync_read_file(self.globals_path)
            globals_contents = yaml.load(globals_data)
            self.file_contents[self.globals_path] = globals_contents
            globals_contents = self.filter_jinja2(globals_contents)
            for key, value in globals_contents.items():
                ansible_property = AnsibleProperty(key, value,
                                                   GLOBALS_FILENAME)
                self.properties.append(ansible_property)
                self.unique_properties[key] = ansible_property
        except Exception as e:
            raise e