Exemplo n.º 1
0
 def test_validate_roles(self):
     available_roles = ['a', 'b', 'c']
     requested_roles = ['b', 'c']
     try:
         rolesutils.check_role_exists(available_roles, requested_roles)
     except Exception:
         self.fail('Exception raised')
Exemplo n.º 2
0
 def test_validate_roles(self):
     available_roles = ['a', 'b', 'c']
     requested_roles = ['b', 'c']
     try:
         rolesutils.check_role_exists(available_roles, requested_roles)
     except Exception:
         self.fail('Exception raised')
Exemplo n.º 3
0
    def take_action(self, parsed_args):
        """Generate roles_data.yaml from imputed roles

        From the provided roles, validate that we have yaml files for the each
        role in our roles path and print them out concatenated together in the
        order they were provided.
        """
        self.log.debug('take_action({})'.format(parsed_args))
        roles_path = os.path.realpath(parsed_args.roles_path)
        # eliminate any dupes from the command line with an OrderedDict
        requested_roles = collections.OrderedDict.fromkeys(parsed_args.roles)
        available_roles = rolesutils.get_roles_list_from_directory(roles_path)
        rolesutils.check_role_exists(available_roles,
                                     list(requested_roles.keys()))
        self._capture_output(parsed_args.output_file)
        roles_data = rolesutils.generate_roles_data_from_directory(
            roles_path, list(requested_roles.keys()),
            parsed_args.skip_validate)
        sys.stdout.write(roles_data)
Exemplo n.º 4
0
    def run(self, context):
        err_msg = ""
        # validate roles in input exist in roles directory in t-h-t
        try:
            roles_utils.check_role_exists(
                [role['name'] for role in self.available_roles],
                [role['name'] for role in self.roles])
        except Exception as chk_err:
            err_msg = str(chk_err)

        # validate role yaml
        for role in self.roles:
            try:
                roles_utils.validate_role_yaml(yaml.safe_dump([role]))
            except exception.RoleMetadataError as rme:
                if 'name' in role:
                    err_msg += "\n%s for %s" % (str(rme), role['name'])
                else:
                    err_msg += "\n%s" % str(rme)

        if err_msg:
            return actions.Result(error=err_msg)
        return actions.Result(data=True)
Exemplo n.º 5
0
    def run(self, context):
        err_msg = ""
        # validate roles in input exist in roles directory in t-h-t
        try:
            roles_utils.check_role_exists(
                [role['name'] for role in self.available_roles],
                [role['name'] for role in self.roles])
        except Exception as chk_err:
            err_msg = str(chk_err)

        # validate role yaml
        for role in self.roles:
            try:
                roles_utils.validate_role_yaml(yaml.safe_dump([role]))
            except exception.RoleMetadataError as rme:
                if 'name' in role:
                    err_msg += "\n%s for %s" % (str(rme), role['name'])
                else:
                    err_msg += "\n%s" % str(rme)

        if err_msg:
            return actions.Result(error=err_msg)
        return actions.Result(data=True)