def get_services(token, api_url): """ Ask OpenStack Keystone for a list of services """ api_cmd = api_url + "/services" response = rest_api_request(token, "GET", api_cmd) return keystone.ServiceList(response)
def _test_region_config(tmpdir, inputfile, resultfile, mock_get_wrsroot_sig): """ Test import and generation of answerfile """ mock_get_wrsroot_sig.return_value = None # Create the path to the output file outputfile = os.path.join(str(tmpdir), 'output') # Parse the region_config file region_config = cr.parse_system_config(inputfile) # Dump results for debugging print("Parsed region_config:\n") _dump_config(region_config) # Validate the region config file cr.create_cgcs_config_file(outputfile, region_config, keystone.ServiceList(FAKE_SERVICE_DATA), keystone.EndpointList(FAKE_ENDPOINT_DATA), keystone.DomainList(FAKE_DOMAIN_DATA)) # Make a local copy of the results file local_resultfile = os.path.join(str(tmpdir), 'result') shutil.copyfile(resultfile, local_resultfile) # Do a diff between the output and the expected results print("\n\nDiff of output file vs. expected results file:\n") with open(outputfile) as a, open(local_resultfile) as b: a_lines = a.readlines() b_lines = b.readlines() differ = difflib.Differ() diff = differ.compare(a_lines, b_lines) print(''.join(diff)) # Fail the testcase if the output doesn't match the expected results assert filecmp.cmp(outputfile, local_resultfile) # Now test that configassistant can parse this answerfile. We can't # compare the resulting cgcs_config file because the ordering, spacing # and comments are different between the answerfile generated by # systemconfig and ConfigAssistant. test_answerfile._test_answerfile(tmpdir, outputfile, compare_results=False) # Validate the region config file. # Using onboard validation since the validator's reference version number # is only set at build-time when validating offboard validate(region_config, REGION_CONFIG, None, False)