def test_generate_roles_with_two_same_roles(self, get_roles_mock, check_mock): get_roles_mock.return_value = ['sample', 'bar', 'baz'] m = mock.mock_open(read_data=SAMPLE_ROLE) with mock.patch('tripleo_common.utils.roles.open', m) as open_mock: r = rolesutils.generate_roles_data_from_directory( '/roles', ['sample', 'sample:sampleA']) open_mock.assert_any_call('/roles/sample.yaml', 'r') header = '\n'.join( ["#" * 79, "# File generated by TripleO", "#" * 79, ""]) expected = header + SAMPLE_ROLE + SAMPLE_GENERATED_ROLE self.assertEqual(expected, r) get_roles_mock.assert_called_with('/roles') check_mock.assert_called_with(['sample', 'bar', 'baz'], ['sample', 'sample:sampleA'])
def test_generate_roles_with_two_same_roles(self, get_roles_mock, check_mock): get_roles_mock.return_value = ['sample', 'bar', 'baz'] m = mock.mock_open(read_data=SAMPLE_ROLE) with mock.patch('tripleo_common.utils.roles.open', m) as open_mock: r = rolesutils.generate_roles_data_from_directory( '/roles', ['sample', 'sample:sampleA']) open_mock.assert_any_call('/roles/sample.yaml', 'r') header = '\n'.join(["#" * 79, "# File generated by TripleO", "#" * 79, ""]) expected = header + SAMPLE_ROLE + SAMPLE_GENERATED_ROLE self.assertEqual(expected, r) get_roles_mock.assert_called_with('/roles') check_mock.assert_called_with(['sample', 'bar', 'baz'], ['sample', 'sample:sampleA'])
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)
__tht_root_dir = os.path.dirname(os.path.dirname(__file__)) __tht_roles_dir = os.path.join(__tht_root_dir, 'roles') def parse_opts(argv): parser = argparse.ArgumentParser( description='Generate roles_data.yaml for requested roles. NOTE: ' 'This is a stripped down version of what is provided by ' 'the tripleoclient. The tripleoclient should be used for ' 'additional functionality.') parser.add_argument('--roles-path', metavar='<roles directory>', help="Filesystem path containing the roles yaml files", default=__tht_roles_dir) parser.add_argument('roles', nargs="+", metavar='<role>', help='List of roles to use to generate the ' 'roles_data.yaml file') opts = parser.parse_args(argv[1:]) return opts opts = parse_opts(sys.argv) roles = collections.OrderedDict.fromkeys(opts.roles) print( rolesutils.generate_roles_data_from_directory(opts.roles_path, roles.keys()))
import os import sys from tripleo_common.utils import roles as rolesutils __tht_root_dir = os.path.dirname(os.path.dirname(__file__)) __tht_roles_dir = os.path.join(__tht_root_dir, 'roles') def parse_opts(argv): parser = argparse.ArgumentParser( description='Generate roles_data.yaml for requested roles. NOTE: ' 'This is a stripped down version of what is provided by ' 'the tripleoclient. The tripleoclient should be used for ' 'additional functionality.') parser.add_argument('--roles-path', metavar='<roles directory>', help="Filesystem path containing the roles yaml files", default=__tht_roles_dir) parser.add_argument('roles', nargs="+", metavar='<role>', help='List of roles to use to generate the ' 'roles_data.yaml file') opts = parser.parse_args(argv[1:]) return opts opts = parse_opts(sys.argv) roles = collections.OrderedDict.fromkeys(opts.roles) print(rolesutils.generate_roles_data_from_directory(opts.roles_path, roles.keys()))