class VCenterShellDriver (ResourceDriverInterface): def cleanup(self): pass def __init__(self): """ ctor must be without arguments, it is created with reflection at run time """ self.command_orchestrator = CommandOrchestrator() # type: CommandOrchestrator def initialize(self): pass def ApplyConnectivityChanges(self, context, request): return self.command_orchestrator.connect_bulk(context, request) def disconnect_all(self, context, ports): return self.command_orchestrator.disconnect_all(context, ports) def disconnect(self, context, ports, network_name): return self.command_orchestrator.disconnect(context, ports, network_name) def destroy_vm(self, context, ports): return self.command_orchestrator.destroy_vm(context, ports) def destroy_vm_only(self, context, ports): return self.command_orchestrator.destroy_vm_only(context, ports) def remote_refresh_ip(self, context, cancellation_context, ports): return self.command_orchestrator.refresh_ip(context, cancellation_context, ports) def PowerOff(self, context, ports): return self.command_orchestrator.power_off(context, ports) # the name is by the Qualisystems conventions def PowerOn(self, context, ports): """ Powers off the remote vm :param models.QualiDriverModels.ResourceRemoteCommandContext context: the context the command runs on :param list[string] ports: the ports of the connection between the remote resource and the local resource, NOT IN USE!!! """ return self.command_orchestrator.power_on(context, ports) # the name is by the Qualisystems conventions def PowerCycle(self, context, ports, delay): return self.command_orchestrator.power_cycle(context, ports, delay) def deploy_from_template(self, context, deploy_data): return self.command_orchestrator.deploy_from_template(context, deploy_data) def deploy_from_image(self, context, deploy_data): return self.command_orchestrator.deploy_from_image(context, deploy_data) def get_inventory(self, context): """ :type context: models.QualiDriverModels.AutoLoadCommandContext """ validator = VCenterAutoModelDiscovery() return validator.validate_and_discover(context)
class TestCommandOrchestrator(TestCase): def setUp(self): self.resource = create_autospec(ResourceInfo) self.resource.ResourceModelName = 'VMwarev Center' self.resource.ResourceAttributes = {'User': '******', 'Password': '******', 'Default dvSwitch': 'switch1', 'Holding Network': 'anetwork', 'Default Port Group Location': 'Quali', 'VM Cluster': 'Quali', 'VM Location': 'Quali', 'VM Resource Pool': 'Quali', 'VM Storage': 'Quali', 'Shutdown Method': 'hard', 'OVF Tool Path': 'C\\program files\ovf', 'Execution Server Selector': '', 'Reserved Networks': 'vlan65', 'Default Datacenter': 'QualiSB' } self.context = Mock() session = Mock() remote_resource = Mock() remote_resource.fullname = 'this is full name of the remote resource' remote_resource.uuid = 'this is full uuis of the remote resource' self.connection_details = Mock() self.context.resource = self.resource self.context.remote_endpoints = [self.resource] self.command_orchestrator = CommandOrchestrator() self.command_orchestrator.command_wrapper.execute_command_with_connection = Mock(return_value=True) self.command_orchestrator.cs_helper = Mock() self.command_orchestrator.cs_helper.get_session = Mock(return_value=session) self.command_orchestrator.cs_helper.get_connection_details = Mock(return_value=self.connection_details) self.ports = [Mock()] self.command_orchestrator._parse_remote_model = Mock(return_value=remote_resource) def test_disconnect_all(self): # act self.command_orchestrator.disconnect_all(self.context, self.ports) # assert self.assertTrue(self.command_orchestrator.command_wrapper.execute_command_with_connection.called) def test_disconnect(self): # act self.command_orchestrator.disconnect(self.context, self.ports, 'network') # assert self.assertTrue(self.command_orchestrator.command_wrapper.execute_command_with_connection.called) def test_destroy_vm(self): # act self.command_orchestrator.destroy_vm(self.context, self.ports) # assert self.assertTrue(self.command_orchestrator.command_wrapper.execute_command_with_connection.called) def test_deploy_from_template(self): # act self.command_orchestrator.deploy_from_template(self.context, '{"name": "name", "template_resource_model": {"vcenter_template": ""}}') # assert self.assertTrue(self.command_orchestrator.command_wrapper.execute_command_with_connection.called) def test_deploy_from_image(self): # act self.command_orchestrator.deploy_from_image(self.context, '{"name": "name"}') # assert self.assertTrue(self.command_orchestrator.command_wrapper.execute_command_with_connection.called) def test_power_off(self): # act self.command_orchestrator.power_off(self.context, self.ports) # assert self.assertTrue(self.command_orchestrator.command_wrapper.execute_command_with_connection.called) def test_power_on(self): # act self.command_orchestrator.power_on(self.context, self.ports) # assert self.assertTrue(self.command_orchestrator.command_wrapper.execute_command_with_connection.called) def test_power_cycle(self): # act self.command_orchestrator.power_cycle(self.context, self.ports, 0.0001) # assert self.assertTrue(self.command_orchestrator.command_wrapper.execute_command_with_connection.called) def test_refresh_ip(self): # act cancellation_context = object() self.command_orchestrator.refresh_ip(self.context, cancellation_context=cancellation_context, ports=self.ports) # assert self.assertTrue(self.command_orchestrator.command_wrapper.execute_command_with_connection.called)