def test_add_file_metadata(self): # tests case where files have no metadata yet plan_files_with_metadata = add_file_metadata(PLAN_DATA_NO_META) self.assertEqual(PLAN_DATA, plan_files_with_metadata, "Metadata not added properly") # tests case where files already have a metadata dict per file for k, v in PLAN_DATA.items(): if 'meta' in v: v.update({'enabled': 'True'}) else: v['meta'] = {'enabled': 'True'} for k, v in PLAN_DATA_NO_META.items(): if 'meta' in v: v.update({'enabled': 'True'}) else: v['meta'] = {'enabled': 'True'} plan_files_with_metadata = add_file_metadata(PLAN_DATA_NO_META) self.assertEqual(PLAN_DATA, plan_files_with_metadata, "Metadata not added properly") # test to ensure having more than one capabilities-map file # results in an exception PLAN_DATA_NO_META.update({ 'capabilities-map2.yaml': { 'contents': MAPPING_YAML_CONTENTS, 'meta': { 'file-type': 'capabilities-map' } } }) self.assertRaises(exception.TooManyCapabilitiesMapFilesError, add_file_metadata, PLAN_DATA_NO_META)
def test_add_file_metadata(self): # tests case where files have no metadata yet plan_files_with_metadata = add_file_metadata(PLAN_DATA_NO_META) self.assertEqual( PLAN_DATA, plan_files_with_metadata, "Metadata not added properly" ) # tests case where files already have a metadata dict per file for k, v in PLAN_DATA.items(): if 'meta' in v: v.update({'enabled': 'True'}) else: v['meta'] = {'enabled': 'True'} for k, v in PLAN_DATA_NO_META.items(): if 'meta' in v: v.update({'enabled': 'True'}) else: v['meta'] = {'enabled': 'True'} plan_files_with_metadata = add_file_metadata(PLAN_DATA_NO_META) self.assertEqual( PLAN_DATA, plan_files_with_metadata, "Metadata not added properly" ) # test to ensure having more than one capabilities-map file # results in an exception PLAN_DATA_NO_META.update({ 'capabilities-map2.yaml': { 'contents': MAPPING_YAML_CONTENTS, 'meta': {'file-type': 'capabilities-map'} } }) self.assertRaises(exception.TooManyCapabilitiesMapFilesError, add_file_metadata, PLAN_DATA_NO_META)
def create_plan(self, plan_name, plan_files): """Creates a plan to store templates Creates a plan by creating a container matching plan_name, and import given plan_files into it. The plan files is a dictionary where the keys are filenames and the values are file contents. :param plan_name: The name of the plan to use as the container name :type plan_name: str :param plan_files: The files to import into the container. :type plan_files: dict """ # create container with versioning try: self.plan_store.create(plan_name) except Exception: LOG.exception("Error creating plan.") raise plan_files = meta.add_file_metadata(plan_files) return self.update_plan(plan_name, plan_files)