def test_disconnect_all(self):
        # arrange
        connection_details = Mock()
        virtual_switch_disconnect_command = Mock()
        virtual_switch_disconnect_command.disconnect_all = Mock(return_value=True)
        command_executer_service = CommandExecuterService(Mock(),
                                                          Mock(),
                                                          self.command_wrapper,
                                                          Mock(),
                                                          Mock(),
                                                          Mock(),
                                                          Mock(),
                                                          Mock(),
                                                          virtual_switch_disconnect_command,
                                                          Mock(),
                                                          Mock())

        CommandContextMocker.set_vm_uuid_param(VmContext.VM_UUID)
        CommandContextMocker.set_command_param(VmContext.NETWORK_NAME, VmContext.NETWORK_NAME)

        # act
        command_executer_service.disconnect_all()

        # assert
        self.assertTrue(self.command_wrapper.execute_command_with_connection
                        .called_with(connection_details,
                                     virtual_switch_disconnect_command.disconnect_all,
                                     VmContext.VM_UUID))
    def test_destroyVirtualMachineCommand(self):
        # arrange
        vcenter_name = 'name'
        resource_att = Mock()
        Destroyer = Mock()
        connection_retriever = Mock()
        connection_details = Mock()

        resource_att.fullname = 'full_name'
        connection_retriever.getVCenterInventoryPathAttributeData = \
            Mock(return_value={'vCenter_resource_name': vcenter_name})
        connection_retriever.connection_details = Mock(return_value=connection_details)
        self.quali_helpers.get_resource_context_details = Mock(return_value=resource_att)
        Destroyer.power_off = Mock(return_value=True)

        command_executer_service = CommandExecuterService(self.serializer,
                                                          self.quali_helpers,
                                                          self.command_wrapper,
                                                          connection_retriever,
                                                          self.vc_center_model,
                                                          Destroyer,
                                                          Mock(),
                                                          Mock(),
                                                          Mock(),
                                                          Mock(),
                                                          Mock())

        CommandContextMocker.set_vm_uuid_param(VmContext.VM_UUID)

        # act
        command_executer_service.destroy_vm()

        # assert
        self.assertTrue(connection_retriever.getVCenterInventoryPathAttributeData.called_with(resource_att))
        self.assertTrue(self.command_wrapper.execute_command_with_connection.called_with(connection_details,
                                                                                         Destroyer.destroy,
                                                                                         VmContext.VM_UUID,
                                                                                         resource_att.fullname))
        self.assertTrue(connection_retriever.connection_details.called_with(vcenter_name))
Пример #3
0
    def test_disconnect(self):
        # arrange
        connection_details = Mock()
        virtual_switch_disconnect_command = Mock()
        virtual_switch_disconnect_command.disconnect = Mock(return_value=True)
        command_executer_service = CommandExecuterService(
            Mock(), Mock(), self.command_wrapper, Mock(), Mock(), Mock(),
            Mock(), Mock(), virtual_switch_disconnect_command, Mock(), Mock())

        CommandContextMocker.set_vm_uuid_param(VmContext.VM_UUID)
        CommandContextMocker.set_command_param(VmContext.NETWORK_NAME,
                                               VmContext.NETWORK_NAME)

        # act
        command_executer_service.disconnect()

        # assert
        self.assertTrue(
            self.command_wrapper.execute_command_with_connection.called_with(
                connection_details,
                virtual_switch_disconnect_command.disconnect,
                VmContext.VM_UUID, VmContext.NETWORK_NAME))
Пример #4
0
    def test_power_off(self):
        # arrange
        vcenter_name = 'name'
        resource_att = Mock()
        power_manager = Mock()
        connection_retriever = Mock()
        connection_details = Mock()
        command_wrapper = Mock()

        connection_retriever.getVCenterInventoryPathAttributeData = \
            Mock(return_value={'vCenter_resource_name': vcenter_name})
        connection_retriever.connection_details = Mock(
            return_value=connection_details)
        self.quali_helpers.get_resource_context_details = Mock(
            return_value=resource_att)
        power_manager.power_off = Mock(return_value=True)

        command_executer_service = CommandExecuterService(
            self.serializer, self.quali_helpers, self.command_wrapper,
            connection_retriever, self.vc_center_model, Mock(), Mock(), Mock(),
            Mock(), Mock(), power_manager)

        CommandContextMocker.set_vm_uuid_param(VmContext.VM_UUID)

        # act
        command_executer_service.power_off()

        # assert
        self.assertTrue(
            connection_retriever.getVCenterInventoryPathAttributeData.
            called_with(resource_att))
        self.assertTrue(
            command_wrapper.execute_command_with_connection.called_with(
                connection_details, power_manager.power_off,
                VmContext.VM_UUID))
        self.assertTrue(
            connection_retriever.connection_details.called_with(vcenter_name))