def test_inventory_preparation(self): (groups, hostvars) = inventory._prepare_inventory() self.assertIn("baremetal", groups) self.assertIn("localhost", groups) self.assertDictEqual(hostvars, {}) localhost_value = dict(hosts=["127.0.0.1"]) self.assertDictEqual(localhost_value, groups['localhost'])
def test__process_shade_multiple_nics(self): inventory.shade = mock_shade = mock.Mock() inventory.SHADE_LOADED = True (groups, hostvars) = inventory._prepare_inventory() mock_cloud = mock_shade.operator_cloud.return_value mock_cloud.list_machines.return_value = [ { 'driver_info': { 'ipmi_address': '1.2.3.4', }, 'links': [], 'name': 'node1', 'ports': [], 'properties': { 'cpus': 42, }, 'uuid': 'f3fbf7c6-b4e9-4dd2-8ca0-c74a50f8be45', }, ] mock_cloud.list_nics_for_machine.return_value = [ { 'address': '00:11:22:33:44:55', 'uuid': 'e2be93b5-a8f6-46a2-bec7-571b8ecf2938', }, { 'address': '00:11:22:33:44:56', 'uuid': '59e8cd37-4f71-4ca1-a264-93c2ca7de0f7', }, ] (groups, hostvars) = inventory._process_shade(groups, hostvars) mock_shade.operator_cloud.assert_called_once_with( auth_type='None', auth={'endpoint': 'http://localhost:6385/'}) mock_cloud.list_machines.assert_called_once_with() mock_cloud.list_nics_for_machine.assert_called_once_with( 'f3fbf7c6-b4e9-4dd2-8ca0-c74a50f8be45') self.assertIn('baremetal', groups) self.assertIn('hosts', groups['baremetal']) self.assertEqual(groups['baremetal'], {'hosts': ['node1']}) self.assertIn('node1', hostvars) expected_machine = { 'addressing_mode': 'dhcp', 'driver_info': { 'ipmi_address': '1.2.3.4', }, 'name': 'node1', 'nics': [ { 'mac': '00:11:22:33:44:55', }, { 'mac': '00:11:22:33:44:56', }, ], 'properties': { 'cpus': 42, }, 'uuid': 'f3fbf7c6-b4e9-4dd2-8ca0-c74a50f8be45', } self.assertEqual(hostvars['node1'], expected_machine)
def bifrost_csv_conversion(csv_data): # TODO(TheJulia): To call prep feels like a bug and should be fixed. (groups, hostvars) = inventory._prepare_inventory() with temporary_file(csv_data) as file: (groups, hostvars) = inventory._process_baremetal_csv(file, groups, hostvars) # NOTE(TheJulia): Returning separately so the file is closed first return (groups, hostvars)
def bifrost_data_conversion(data): (groups, hostvars) = inventory._prepare_inventory() with temporary_file(data) as file: (groups, hostvars) = inventory._process_baremetal_data( file, groups, hostvars) return (groups, hostvars)
def test__process_sdk_multiple_nics(self, mock_sdk): (groups, hostvars) = inventory._prepare_inventory() mock_cloud = mock_sdk.return_value mock_cloud.list_machines.return_value = [ { 'driver_info': { 'ipmi_address': '1.2.3.4', }, 'links': [], 'name': 'node1', 'ports': [], 'properties': { 'cpus': 42, }, 'uuid': 'f3fbf7c6-b4e9-4dd2-8ca0-c74a50f8be45', }, ] mock_cloud.list_nics_for_machine.return_value = [ { 'address': '00:11:22:33:44:55', 'uuid': 'e2be93b5-a8f6-46a2-bec7-571b8ecf2938', }, { 'address': '00:11:22:33:44:56', 'uuid': '59e8cd37-4f71-4ca1-a264-93c2ca7de0f7', }, ] (groups, hostvars) = inventory._process_sdk(groups, hostvars) mock_cloud.list_machines.assert_called_once_with() mock_cloud.list_nics_for_machine.assert_called_once_with( 'f3fbf7c6-b4e9-4dd2-8ca0-c74a50f8be45') self.assertIn('baremetal', groups) self.assertIn('hosts', groups['baremetal']) self.assertEqual(groups['baremetal'], {'hosts': ['node1']}) self.assertIn('node1', hostvars) expected_machine = { 'addressing_mode': 'dhcp', 'driver_info': { 'ipmi_address': '1.2.3.4', }, 'name': 'node1', 'nics': [ { 'mac': '00:11:22:33:44:55', }, { 'mac': '00:11:22:33:44:56', }, ], 'properties': { 'cpus': 42, }, 'uuid': 'f3fbf7c6-b4e9-4dd2-8ca0-c74a50f8be45', } self.assertEqual(hostvars['node1'], expected_machine)
def bifrost_csv_conversion(csv_data): # TODO(TheJulia): To call prep feels like a bug and should be fixed. (groups, hostvars) = inventory._prepare_inventory() with temporary_file(csv_data) as file: (groups, hostvars) = inventory._process_baremetal_csv( file, groups, hostvars) # NOTE(TheJulia): Returning separately so the file is closed first return (groups, hostvars)
def test__process_shade(self): inventory.shade = mock_shade = mock.Mock() inventory.SHADE_LOADED = True (groups, hostvars) = inventory._prepare_inventory() mock_cloud = mock_shade.operator_cloud.return_value mock_cloud.list_machines.return_value = [ { 'driver_info': { 'ipmi_address': '1.2.3.4', }, 'links': [], 'name': 'node1', 'ports': [], 'properties': { 'cpus': 42, }, 'uuid': 'f3fbf7c6-b4e9-4dd2-8ca0-c74a50f8be45', }, ] mock_cloud.list_nics_for_machine.return_value = [ { 'address': '00:11:22:33:44:55', 'uuid': 'e2be93b5-a8f6-46a2-bec7-571b8ecf2938', }, ] (groups, hostvars) = inventory._process_shade(groups, hostvars) mock_shade.operator_cloud.assert_called_once_with( auth_type='None', auth={'endpoint': 'http://localhost:6385/'}) mock_cloud.list_machines.assert_called_once_with() mock_cloud.list_nics_for_machine.assert_called_once_with( 'f3fbf7c6-b4e9-4dd2-8ca0-c74a50f8be45') self.assertIn('baremetal', groups) self.assertIn('hosts', groups['baremetal']) self.assertEqual(groups['baremetal'], {'hosts': ['node1']}) self.assertIn('node1', hostvars) expected_machine = { 'addressing_mode': 'dhcp', 'driver_info': { 'ipmi_address': '1.2.3.4', }, 'name': 'node1', 'nics': [ { 'mac': '00:11:22:33:44:55', }, ], 'properties': { 'cpus': 42, }, 'uuid': 'f3fbf7c6-b4e9-4dd2-8ca0-c74a50f8be45', } self.assertEqual(hostvars['node1'], expected_machine)
def bifrost_data_conversion(data): (groups, hostvars) = inventory._prepare_inventory() with temporary_file(data) as file: (groups, hostvars) = inventory._process_baremetal_data(file, groups, hostvars) return (groups, hostvars)