def test_deploy_execute(self):
        # arrange
        deployer = Mock()
        si = Mock()
        template_model = Mock()

        deploy_res = dict()
        deploy_res['vm_path'] = 'path'
        deploy_res['vm_name'] = 'name'
        deploy_res['uuid'] = 'uuid'

        template_model.template_name = 'temp name'
        template_model.vm_folder = 'temp folder'
        deployer.deploy_from_template = Mock(return_value=deploy_res)

        deploy_params = DeployDataHolder.create_from_params(template_model,
                                                            'datastore_name',
                                                            'vm_cluster_model',
                                                            'power_on')

        deploy_command = DeployFromTemplateCommand(deployer)

        # act
        result = deploy_command.execute_deploy_from_template(si, deploy_params)

        # assert
        self.assertTrue(result)
        self.assertTrue(deployer.deploy_from_template.called_with(si, deploy_params))
    def test_vm_deployer_error(self):
        name = 'name'
        name_gen = Mock(return_value=name)
        pv_service = Mock()
        si = Mock()
        clone_parmas = Mock()
        clone_res = Mock()
        clone_res.error = Mock()

        pv_service.CloneVmParameters = Mock(return_value=clone_parmas)
        pv_service.clone_vm = Mock(return_value=clone_res)
        params = DeployDataHolder.create_from_params(
            template_model={
                "vCenter_resource_name": "vcenter_resource_name",
                "vm_folder": "vfolder_name",
                "template_name": "template_name"
            },
            vm_cluster_model={
                "cluster_name": "cluster_name",
                "resource_pool": "resource_pool"
            },
            datastore_name="datastore_name",
            power_on=False)

        deployer = VirtualMachineDeployer(pv_service, name_gen)

        self.assertRaises(Exception, deployer.deploy_from_template, si, params)
        self.assertTrue(pv_service.CloneVmParameters.called)
Example #3
0
    def _get_data_holder(self):
        resource_context = helpers.get_resource_context_details()

        # get vCenter resource name, template name, template folder
        template_model = self.cs_retriever_service.getVCenterTemplateAttributeData(resource_context)
        # get power state of the cloned VM
        power_on = self.cs_retriever_service.getPowerStateAttributeData(resource_context)
        # get cluster and resource pool
        vm_cluster_model = self.cs_retriever_service.getVMClusterAttributeData(resource_context)
        # get datastore
        datastore_name = self.cs_retriever_service.getVMStorageAttributeData(resource_context)

        return DeployDataHolder.create_from_params(template_model=template_model,
                                                   datastore_name=datastore_name,
                                                   vm_cluster_model=vm_cluster_model,
                                                   power_on=power_on)
    def test_vm_deployer(self):
        name = 'name'
        uuid = 'uuid'
        name_gen = Mock(return_value=name)
        pv_service = Mock()
        si = Mock()
        clone_parmas = Mock()
        clone_res = Mock()
        clone_res.error = None
        clone_res.vm = Mock()
        clone_res.vm.summary = Mock()
        clone_res.vm.summary.config = Mock()
        clone_res.vm.summary.config.uuid = uuid

        pv_service.CloneVmParameters = Mock(return_value=clone_parmas)
        pv_service.clone_vm = Mock(return_value=clone_res)
        params = DeployDataHolder({
            "resource_context": None,
            "template_model": {
                "vCenter_resource_name": "vcenter_resource_name",
                "vm_folder": "vfolder_name",
                "template_name": "template_name"
            },
            "vm_cluster_model": {
                "cluster_name": "cluster_name",
                "resource_pool": "resource_pool"
            },
            "datastore_name": "datastore_name",
            "power_on": False
        })

        deployer = VirtualMachineDeployer(pv_service, name_gen)
        res = deployer.deploy_from_template(si, params)

        self.assertEqual(res.vm_name, name)
        self.assertEqual(res.vm_uuid, uuid)
        self.assertEqual(res.cloud_provider_resource_name,
                         params.template_model.vCenter_resource_name)
        self.assertTrue(pv_service.CloneVmParameters.called)