def test_with_description(self): ansible_module_parameters = { 'domain_type': 'kvm', 'name': 'vm-foo', 'resources': { 'description': ('Some long human readable description for the ' 'domain.') } } ansible_module_parameters = self.ansible_module_defaults ansible_module_parameters['resources']['description'] = ( 'Some long ' 'human readable description for the domain.') ansible_module = MockAnsibleModule( parameters=ansible_module_parameters) module_to_intermediate = ModuleToIntermediate( libvirt_domain_module=ansible_module) description_filter_list = list( filter(lambda x: x['element_name'] == 'description', module_to_intermediate.representation['children'])) self.assertEqual(len(description_filter_list), 1) description_dict = description_filter_list[0] self.assertIn('element_name', description_dict) self.assertEqual(description_dict['element_name'], 'description') self.assertIn('text', description_dict) self.assertEqual( description_dict['text'], 'Some long human readable ' 'description for the domain.')
def setUpClass(cls): cls.ansible_module_defaults = MockAnsibleModule.DEFAULT_PARAMETERS cls.ansible_module_defaults['name'] = \ MockAnsibleModule.DEFAULT_DOMAIN_NAME ansible_module = MockAnsibleModule( parameters=cls.ansible_module_defaults) cls.module_to_intermediate = ModuleToIntermediate( libvirt_domain_module=ansible_module)
def test_xml_and_module_comparison(self): ansible_module = self.get_anisble_module() module_intermediate = ModuleToIntermediate( libvirt_domain_module=ansible_module) filtered_xml = self.get_filtered_xml() domain_intermediate = XmlToIntermediate(xml_string=filtered_xml) self.assertEqual(module_intermediate.representation, domain_intermediate.representation)
def test_null_description(self): ansible_module_parameters = self.ansible_module_defaults ansible_module_parameters['resources']['description'] = None ansible_module = MockAnsibleModule( parameters=ansible_module_parameters) module_to_intermediate = ModuleToIntermediate( libvirt_domain_module=ansible_module) description_filter_list = list( filter(lambda x: x['element_name'] == 'description', module_to_intermediate.representation['children'])) self.assertFalse(description_filter_list)
def test_with_title(self): ansible_module_parameters = self.ansible_module_defaults ansible_module_parameters['resources']['title'] = ('domain short ' 'description') ansible_module = MockAnsibleModule( parameters=ansible_module_parameters) module_to_intermediate = ModuleToIntermediate( libvirt_domain_module=ansible_module) title_filter_list = list( filter(lambda x: x['element_name'] == 'title', module_to_intermediate.representation['children'])) self.assertEqual(len(title_filter_list), 1) title_dict = title_filter_list[0] self.assertIn('element_name', title_dict) self.assertEqual(title_dict['element_name'], 'title') self.assertIn('text', title_dict) self.assertEqual(title_dict['text'], 'domain short description')
def test_null_uuid(self): ansible_module_parameters = self.ansible_module_defaults ansible_module_parameters['resources']['uuid'] = None ansible_module = MockAnsibleModule( parameters=ansible_module_parameters) module_to_intermediate = ModuleToIntermediate( libvirt_domain_module=ansible_module) uuid_filter_list = list( filter(lambda x: x['element_name'] == 'uuid', module_to_intermediate.representation['children'])) self.assertEqual(len(uuid_filter_list), 1) uuid_dict = uuid_filter_list[0] self.assertIn('element_name', uuid_dict) self.assertEqual(uuid_dict['element_name'], 'uuid') self.assertIn('text', uuid_dict) self.assertEqual(uuid_dict['text'], MockAnsibleModule.DEFAULT_AUTO_GENERATED_UUID)
def test_with_uuid(self): ansible_module_parameters = self.ansible_module_defaults sample_uuid = '4b77c8d5-61d8-45e9-a132-86f4d1f6f2f9' ansible_module_parameters['resources']['uuid'] = sample_uuid ansible_module = MockAnsibleModule( parameters=ansible_module_parameters) module_to_intermediate = ModuleToIntermediate( libvirt_domain_module=ansible_module) uuid_filter_list = list( filter(lambda x: x['element_name'] == 'uuid', module_to_intermediate.representation['children'])) self.assertEqual(len(uuid_filter_list), 1) uuid_dict = uuid_filter_list[0] self.assertIn('element_name', uuid_dict) self.assertEqual(uuid_dict['element_name'], 'uuid') self.assertIn('text', uuid_dict) self.assertEqual(uuid_dict['text'], sample_uuid)