|
| 1 | +import uuid |
| 2 | +from unittest import TestCase |
| 3 | + |
| 4 | +import jsonpickle |
| 5 | +from pyVmomi import vim |
| 6 | +from mock import Mock, create_autospec, patch |
| 7 | +from pyVmomi.VmomiSupport import vmodlNames |
| 8 | + |
| 9 | +from static_vm_package.VCenterAutoloadStaticVMDriver.app_discovery.vm_autoload_driver import \ |
| 10 | + DeployAppOrchestrationDriver |
| 11 | + |
| 12 | + |
| 13 | +class TestGetInventory(TestCase): |
| 14 | + def setUp(self): |
| 15 | + self.deploy_app_orchestration_driver = DeployAppOrchestrationDriver() |
| 16 | + self.context = Mock() |
| 17 | + self.context.resource.attributes = Mock() |
| 18 | + self.VMLoader = Mock() |
| 19 | + |
| 20 | + def test_get_inventory(self): |
| 21 | + vcenter_data_model = Mock() |
| 22 | + vcenter_data_model.default_datacenter = 'name' |
| 23 | + self.deploy_app_orchestration_driver.cs_helper.get_session = Mock(return_value=Mock()) |
| 24 | + self.deploy_app_orchestration_driver.model_parser.convert_to_vcenter_model = Mock( |
| 25 | + return_value=vcenter_data_model) |
| 26 | + self.deploy_app_orchestration_driver._get_connection_to_vcenter = Mock(return_value=Mock()) |
| 27 | + self.deploy_app_orchestration_driver._try_get_ip = Mock(return_value=Mock()) |
| 28 | + self.deploy_app_orchestration_driver._get_vm_details = Mock(return_value=Mock()) |
| 29 | + self.deploy_app_orchestration_driver.pv_service.find_vm_by_name = Mock( |
| 30 | + return_value=vim.VirtualMachine(Mock(), Mock())) |
| 31 | + |
| 32 | + # deployer.deploy_from_image = Mock(return_value=res) |
| 33 | + self.context.resource.attributes = {'vCenter VM': 'dd', 'vCenter Name': 'd2'} |
| 34 | + |
| 35 | + self.logger = Mock() |
| 36 | + # Act |
| 37 | + |
| 38 | + self.deploy_app_orchestration_driver.get_inventory(self.context) |
| 39 | + # Assert |
| 40 | + |
| 41 | + self.assertTrue(self.deploy_app_orchestration_driver.model_parser.convert_to_vcenter_model.called) |
| 42 | + self.assertTrue(self.deploy_app_orchestration_driver.cs_helper.get_session.called) |
| 43 | + self.assertTrue(self.deploy_app_orchestration_driver.model_parser.convert_to_vcenter_model.valled) |
| 44 | + self.assertTrue(self.deploy_app_orchestration_driver._get_connection_to_vcenter.called) |
| 45 | + self.assertTrue(self.deploy_app_orchestration_driver._try_get_ip.called) |
| 46 | + self.assertTrue(self.deploy_app_orchestration_driver._get_vm_details.called) |
| 47 | + self.assertTrue(self.deploy_app_orchestration_driver.pv_service.find_vm_by_name.called) |
| 48 | + |
| 49 | + def test_get_vm_details(self): |
| 50 | + vm_details = self.deploy_app_orchestration_driver._get_vm_details(uuid="Piplup", |
| 51 | + vcenter_name="Prinplup", |
| 52 | + resource="Empoleon") |
| 53 | + str_vm_details = jsonpickle.decode(vm_details) |
| 54 | + self.assertTrue(str_vm_details['CloudProviderName']=="Prinplup") |
| 55 | + self.assertTrue(str_vm_details['UID']=='Piplup') |
| 56 | + |
| 57 | + |
| 58 | + |
0 commit comments