def test_deploy_image_error(self):

        PROCESS.communicate = Mock(return_value=['error'])
        ovf = OvfImageDeployerService('dummypath/ovftool.exe')
        image_params = Mock()
        image_params.connectivity = VCenterConnectionDetails('venter.host.com', 'vcenter user', 'password to vcenter')
        image_params.datacenter = 'QualiSB'
        image_params.cluster = 'QualiSB Cluster'
        image_params.resource_pool = 'LiverPool'
        image_params.vm_name = 'raz_deploy_image_integration_test'
        image_params.datastore = 'aa'
        # image_params.image_url = "C:\\images\\test\\OVAfile121_QS\\OVAfile121_QS.ovf"
        image_params.image_url = "http://192.168.65.88/ovf/Debian 64 - Yoav.ovf"

        image_params.user_arguments = '--vlan="anetwork"'

        ovf._validate_url_exists = Mock(return_value=True)

        vcenter_data_model = Mock()
        vcenter_data_model.ovf_tool_path = 'dummypath/ovftool.exe'

        try:
            ovf.deploy_image(vcenter_data_model, image_params, logger=Mock())
            # should not reach here
            self.assertTrue(False)
        except Exception as inst:
            self.assertTrue(inst.message.find('password to vcenter') == -1)
            self.assertTrue(inst.message.find(urllib.quote_plus('******')) > -1)
            self.assertTrue(PROCESS.stdin.close.called)
    def test_deploy_image_error(self):

        PROCESS.communicate = Mock(return_value=['error'])
        ovf = OvfImageDeployerService('dummypath/ovftool.exe')
        image_params = Mock()
        image_params.connectivity = VCenterConnectionDetails(
            'venter.host.com', 'vcenter user', 'password to vcenter')
        image_params.datacenter = 'QualiSB'
        image_params.cluster = 'QualiSB Cluster'
        image_params.resource_pool = 'LiverPool'
        image_params.vm_name = 'raz_deploy_image_integration_test'
        image_params.datastore = 'aa'
        # image_params.image_url = "C:\\images\\test\\OVAfile121_QS\\OVAfile121_QS.ovf"
        image_params.image_url = "http://192.168.65.88/ovf/Debian 64 - Yoav.ovf"

        image_params.user_arguments = '--vlan="anetwork"'

        ovf._validate_url_exists = Mock(return_value=True)

        vcenter_data_model = Mock()
        vcenter_data_model.ovf_tool_path = 'dummypath/ovftool.exe'

        try:
            ovf.deploy_image(vcenter_data_model, image_params, logger=Mock())
            # should not reach here
            self.assertTrue(False)
        except Exception as inst:
            self.assertTrue(inst.message.find('password to vcenter') == -1)
            self.assertTrue(
                inst.message.find(urllib.quote_plus('******')) > -1)
            self.assertTrue(PROCESS.stdin.close.called)
    def test_deploy_image(self):
        # arrange

        cred = TestCredentials()
        pv_service = pyVmomiService(SmartConnect, Disconnect)
        si = pv_service.connect(cred.host, cred.username, cred.password)
        service = OvfImageDeployerService(
            'C:\\Program Files\\VMware\\VMware OVF Tool\\ovftool.exe', Mock())
        deployer = VirtualMachineDeployer(pv_service, generate_unique_name,
                                          service)

        # vm = pv_service.find_vm_by_name(si, 'QualiSB/Raz', '2')

        params = DeployDataHolder({
            "image_url": "http://192.168.65.88/ovf/Debian%2064%20-%20Yoav.ovf",
            "cluster_name": "QualiSB Cluster",
            "resource_pool": "LiverPool",
            "datastore_name": "datastore1",
            "datacenter_name": "QualiSB",
            "power_on": True,
            "app_name": "appName 1",
            "vm_folder": "Raz 2"
        })

        deploy_command = DeployCommand(deployer)
        # act
        result = deploy_command.execute_deploy_from_image(si, params, cred)

        # assert
        self.assertIsNotNone(result)
    def test_deploy_image_no_communication(self):

        PROCESS.communicate = Mock(return_value=None)
        ovf = OvfImageDeployerService('dummypath/ovftool.exe')
        image_params = Mock()
        image_params.connectivity = VCenterConnectionDetails('venter.host.com', 'vcenter user', 'password to vcenter')

        image_params.datacenter = 'QualiSB'
        image_params.cluster = 'QualiSB Cluster'
        image_params.vm_name = 'raz_deploy_image_integration_test'
        image_params.resource_pool = 'LiverPool'
        image_params.datastore = 'aa'
        # image_params.image_url = "C:\\images\\test\\OVAfile121_QS\\OVAfile121_QS.ovf"
        image_params.image_url = "http://192.168.65.88/ovf/Debian 64 - Yoav.ovf"
        image_params.user_arguments = '--vlan="anetwork"'

        vcenter_data_model = Mock()
        vcenter_data_model.ovf_tool_path = 'dummypath/ovftool.exe'
        ovf._validate_url_exists = Mock(return_value=True)

        self.assertRaises(Exception, ovf.deploy_image, vcenter_data_model, image_params)
        self.assertTrue(PROCESS.stdin.close.called)
    def test_deploy_image_success(self):
        PROCESS.communicate = Mock(return_value=['Completed successfully'])
        expected_args = \
            ['dummypath/ovftool.exe',
             '--noSSLVerify',
             '--acceptAllEulas',
             '--powerOffTarget',
             '--name=raz_deploy_image_integration_test',
             '--datastore=aa',
             '--vmFolder=Raz',
             '--vlan="anetwork"',
             'http://192.168.65.88/ovf/Debian 64 - Yoav.ovf',
             'vi://vcenter%20user:password%20to%[email protected]/QualiSB/host/QualiSB%20Cluster/Resources/LiverPool']
        ovf = OvfImageDeployerService('dummypath/ovftool.exe')
        image_params = Mock()
        image_params.connectivity = VCenterConnectionDetails(
            'venter.host.com', 'vcenter user', 'password to vcenter')

        image_params.datacenter = 'QualiSB'
        image_params.cluster = 'QualiSB Cluster'
        image_params.resource_pool = 'LiverPool'
        image_params.vm_name = 'raz_deploy_image_integration_test'
        image_params.datastore = 'aa'
        image_params.power_on = 'false'
        image_params.vm_folder = 'Raz'
        # image_params.image_url = "C:\\images\\test\\OVAfile121_QS\\OVAfile121_QS.ovf"
        image_params.image_url = "http://192.168.65.88/ovf/Debian 64 - Yoav.ovf"
        image_params.user_arguments = '--vlan="anetwork"'

        vcenter_data_model = Mock()
        vcenter_data_model.ovf_tool_path = 'dummypath/ovftool.exe'

        ovf._validate_url_exists = Mock(return_value=True)

        res = ovf.deploy_image(vcenter_data_model, image_params, logger=Mock())

        self.assertTrue(res)
        self.assertEqual(PROCESS.args, expected_args)
        self.assertTrue(PROCESS.stdin.close.called)
    def test_deploy_image_success(self):
        PROCESS.communicate = Mock(return_value=['Completed successfully'])
        expected_args = \
            ['dummypath/ovftool.exe',
             '--noSSLVerify',
             '--acceptAllEulas',
             '--powerOn',
             '--name=raz_deploy_image_integration_test',
             '--datastore=aa',
             '--vmFolder=Raz',
             '--vlan="anetwork"',
             'http://192.168.65.88/ovf/Debian 64 - Yoav.ovf',
             'vi://vcenter%20user:password%20to%[email protected]/QualiSB/host/QualiSB%20Cluster/Resources/LiverPool']
        ovf = OvfImageDeployerService('dummypath/ovftool.exe')
        image_params = Mock()
        image_params.connectivity = VCenterConnectionDetails('venter.host.com', 'vcenter user', 'password to vcenter')

        image_params.datacenter = 'QualiSB'
        image_params.cluster = 'QualiSB Cluster'
        image_params.resource_pool = 'LiverPool'
        image_params.vm_name = 'raz_deploy_image_integration_test'
        image_params.datastore = 'aa'
        image_params.power_on = 'true'
        image_params.vm_folder = 'Raz'
        # image_params.image_url = "C:\\images\\test\\OVAfile121_QS\\OVAfile121_QS.ovf"
        image_params.image_url = "http://192.168.65.88/ovf/Debian 64 - Yoav.ovf"
        image_params.user_arguments = '--vlan="anetwork"'

        vcenter_data_model = Mock()
        vcenter_data_model.ovf_tool_path = 'dummypath/ovftool.exe'

        ovf._validate_url_exists = Mock(return_value=True)

        res = ovf.deploy_image(vcenter_data_model, image_params, logger=Mock())

        self.assertTrue(res)
        self.assertEqual(PROCESS.args, expected_args)
        self.assertTrue(PROCESS.stdin.close.called)
    def test_deploy_image_no_communication(self):

        PROCESS.communicate = Mock(return_value=None)
        ovf = OvfImageDeployerService('dummypath/ovftool.exe')
        image_params = Mock()
        image_params.connectivity = VCenterConnectionDetails(
            'venter.host.com', 'vcenter user', 'password to vcenter')

        image_params.datacenter = 'QualiSB'
        image_params.cluster = 'QualiSB Cluster'
        image_params.vm_name = 'raz_deploy_image_integration_test'
        image_params.resource_pool = 'LiverPool'
        image_params.datastore = 'aa'
        # image_params.image_url = "C:\\images\\test\\OVAfile121_QS\\OVAfile121_QS.ovf"
        image_params.image_url = "http://192.168.65.88/ovf/Debian 64 - Yoav.ovf"
        image_params.user_arguments = '--vlan="anetwork"'

        vcenter_data_model = Mock()
        vcenter_data_model.ovf_tool_path = 'dummypath/ovftool.exe'
        ovf._validate_url_exists = Mock(return_value=True)

        self.assertRaises(Exception, ovf.deploy_image, vcenter_data_model,
                          image_params)
        self.assertTrue(PROCESS.stdin.close.called)
Пример #8
0
    def __init__(self):
        """
        Initialize the driver session, this function is called everytime a new instance of the driver is created
        in here the driver is going to be bootstrapped

        :param context: models.QualiDriverModels.InitCommandContext
        """
        self.cs_helper = CloudshellDriverHelper()
        synchronous_task_waiter = SynchronousTaskWaiter()
        pv_service = pyVmomiService(connect=SmartConnect,
                                    disconnect=Disconnect,
                                    task_waiter=synchronous_task_waiter)
        self.resource_model_parser = ResourceModelParser()
        port_group_name_generator = DvPortGroupNameGenerator()

        vnic_to_network_mapper = VnicToNetworkMapper(
            quali_name_generator=port_group_name_generator)
        resource_remover = CloudshellResourceRemover()
        ovf_service = OvfImageDeployerService(self.resource_model_parser)

        self.vm_loader = VMLoader(pv_service)

        vm_deployer = VirtualMachineDeployer(
            pv_service=pv_service,
            name_generator=generate_unique_name,
            ovf_service=ovf_service,
            cs_helper=self.cs_helper,
            resource_model_parser=ResourceModelParser())

        dv_port_group_creator = DvPortGroupCreator(
            pyvmomi_service=pv_service,
            synchronous_task_waiter=synchronous_task_waiter)
        virtual_machine_port_group_configurer = \
            VirtualMachinePortGroupConfigurer(pyvmomi_service=pv_service,
                                              synchronous_task_waiter=synchronous_task_waiter,
                                              vnic_to_network_mapper=vnic_to_network_mapper,
                                              vnic_service=VNicService(),
                                              name_gen=port_group_name_generator)
        virtual_switch_to_machine_connector = VirtualSwitchToMachineConnector(
            dv_port_group_creator, virtual_machine_port_group_configurer)
        # Command Wrapper
        self.command_wrapper = CommandWrapper(
            pv_service=pv_service,
            cloud_shell_helper=self.cs_helper,
            resource_model_parser=self.resource_model_parser,
            context_based_logger_factory=ContextBasedLoggerFactory())
        # Deploy Command
        self.deploy_command = DeployCommand(deployer=vm_deployer)

        # Virtual Switch Revoke
        self.virtual_switch_disconnect_command = \
            VirtualSwitchToMachineDisconnectCommand(
                pyvmomi_service=pv_service,
                port_group_configurer=virtual_machine_port_group_configurer,
                resource_model_parser=self.resource_model_parser)

        # Virtual Switch Connect
        virtual_switch_connect_command = \
            VirtualSwitchConnectCommand(
                pv_service=pv_service,
                virtual_switch_to_machine_connector=virtual_switch_to_machine_connector,
                dv_port_group_name_generator=DvPortGroupNameGenerator(),
                vlan_spec_factory=VlanSpecFactory(),
                vlan_id_range_parser=VLanIdRangeParser())
        self.connection_orchestrator = ConnectionCommandOrchestrator(
            connector=virtual_switch_connect_command,
            disconnector=self.virtual_switch_disconnect_command,
            resource_model_parser=self.resource_model_parser)

        # Destroy VM Command
        self.destroy_virtual_machine_command = \
            DestroyVirtualMachineCommand(pv_service=pv_service,
                                         resource_remover=resource_remover,
                                         disconnector=self.virtual_switch_disconnect_command)
        # Power Command
        self.vm_power_management_command = \
            VirtualMachinePowerManagementCommand(pyvmomi_service=pv_service,
                                                 synchronous_task_waiter=synchronous_task_waiter)

        ip_manager = VMIPManager()

        # Refresh IP command
        self.refresh_ip_command = RefreshIpCommand(
            pyvmomi_service=pv_service,
            resource_model_parser=ResourceModelParser(),
            ip_manager=ip_manager)

        # Save Snapshot
        self.snapshot_saver = SaveSnapshotCommand(
            pyvmomi_service=pv_service, task_waiter=synchronous_task_waiter)

        # Snapshot Restorer
        self.snapshot_restorer = SnapshotRestoreCommand(
            pyvmomi_service=pv_service, task_waiter=synchronous_task_waiter)

        self.snapshots_retriever = RetrieveSnapshotsCommand(
            pyvmomi_service=pv_service)