예제 #1
0
    def test_integrationtest_refresh_ip(self):
        resource_context = Mock()
        resource_context.attributes = {
            "vCenter Template": "vCenter/Boris/Boris2-win7"
        }
        qualipy_helpers = Mock()
        qualipy_helpers.get_resource_context_details = Mock(
            return_value=resource_context)

        credentials = TestCredentials()
        py_vmomi_service = pyVmomiService(SmartConnect, Disconnect)
        si = py_vmomi_service.connect(credentials.host, credentials.username,
                                      credentials.password)
        cloudshell_data_retriever_service = Mock()
        cloudshell_data_retriever_service.getVCenterConnectionDetails = Mock(
            return_value=VCenterConnectionDetails(
                credentials.host, credentials.username, credentials.password))

        vm_resource = Mock()
        vm_resource.default_network = 'default'

        resource_model_parser = Mock()
        resource_model_parser.convert_to_resource_model = Mock(
            return_value=vm_resource)

        refresh_ip_command = RefreshIpCommand(
            py_vmomi_service, cloudshell_data_retriever_service,
            qualipy_helpers, resource_model_parser)

        # uuid = helpers.get_uuid('VM Deployment_afee8038')
        ip = refresh_ip_command.refresh_ip(
            si, '4222f613-e714-6204-8095-e282796985fb',
            'VM Deployment_afee8038')
        print ip
        pass
예제 #2
0
    def integrationtest(self):
        resource_connection_details_retriever = Mock()
        credentials = TestCredentials()
        resource_connection_details_retriever.connection_details = Mock(
            return_value=VCenterConnectionDetails(
                credentials.host, credentials.username, credentials.password))
        py_vmomi_service = pyVmomiService(SmartConnect, Disconnect)
        synchronous_task_waiter = SynchronousTaskWaiter()
        dv_port_group_creator = DvPortGroupCreator(py_vmomi_service,
                                                   synchronous_task_waiter)

        pg_name_generator = DvPortGroupNameGenerator
        vnic_to_network_mapper = VnicToNetworkMapper(pg_name_generator)
        virtual_machine_port_group_configurer = VirtualMachinePortGroupConfigurer(
            py_vmomi_service, synchronous_task_waiter, vnic_to_network_mapper,
            VNicService())

        virtual_switch_to_machine_connector = VirtualSwitchToMachineConnector(
            dv_port_group_creator, virtual_machine_port_group_configurer)

        si = py_vmomi_service.connect(credentials.host, credentials.username,
                                      credentials.password, credentials.port)

        virtual_machine_path = 'Boris'
        virtual_machine_name = 'boris1'
        vm = py_vmomi_service.get_obj(si.content, [vim.VirtualMachine],
                                      virtual_machine_name)
        vm_uuid = vm.config.uuid
        #vm_uuid = self.get_vm_uuid(py_vmomi_service, si, virtual_machine_name)
        dv_switch_path = 'QualiSB'
        dv_switch_name = 'dvSwitch'
        dv_port_name = 'boris_group59'
    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)
예제 #4
0
    def integrationtest_refresh_ip(self):
        resource_context = Mock()
        resource_context.attributes = {"vCenter Template": "vCenter/Alex/test"}
        qualipy_helpers = Mock()
        qualipy_helpers.get_resource_context_details = Mock(
            return_value=resource_context)

        credentials = TestCredentials()
        py_vmomi_service = pyVmomiService(SmartConnect, Disconnect)
        cloudshell_data_retriever_service = Mock()
        cloudshell_data_retriever_service.getVCenterConnectionDetails = Mock(
            return_value=VCenterConnectionDetails(
                credentials.host, credentials.username, credentials.password))

        vm_resource = Mock()
        vm_resource.default_network = 'default'

        resource_model_parser = Mock()
        resource_model_parser.convert_to_resource_model = Mock(
            return_value=vm_resource)

        refresh_ip_command = RefreshIpCommand(
            py_vmomi_service, cloudshell_data_retriever_service,
            qualipy_helpers, resource_model_parser)

        uuid = helpers.get_uuid('vCenter-Server-Appliance-yaniv')
        refresh_ip_command.refresh_ip(uuid, '')

        pass
예제 #5
0
    def connection_details(self):
        """ Retrieves connection details to vCenter from specified resource

        :param resource_name: Resource name to get connection details from
        :rtype VCenterConnectionDetails:
        """
        # gets the vcenter resource context to connect. We assume this will only run on a cloud prodvider resource
        session = self.qualipy_helpers.get_api_session()
        resource_context = self.qualipy_helpers.get_resource_context_details()

        # get vCenter connection details from vCenter resource
        user = resource_context.attributes["User"]
        encrypted_pass = resource_context.attributes["Password"]
        vcenter_url = resource_context.address
        password = session.DecryptPassword(encrypted_pass).Value

        return VCenterConnectionDetails(vcenter_url, user, password)
예제 #6
0
    def get_connection_details(self, session, vcenter_resource_model,
                               resource_context):
        """
        Methods retrieves the connection details from the vcenter resource model attributes.

        :param CloudShellAPISession session:
        :param VMwarevCenterResourceModel vcenter_resource_model: Instance of VMwarevCenterResourceModel
        :param ResourceContextDetails resource_context: the context of the command
        """

        # get connection details
        user = vcenter_resource_model.user
        encrypted_pass = vcenter_resource_model.password
        vcenter_url = resource_context.address
        password = session.DecryptPassword(encrypted_pass).Value

        return VCenterConnectionDetails(vcenter_url, user, password)
    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 setUp(self):
        self._si = None

        self.vm = None

        self.virtual_machine_path = 'SergiiT'
        self.virtual_machine_name = 'test_4f383119'
        self.vm_uuid = None

        self.vcenter_name = "QualiSB"
        self.dv_switch_path = 'QualiSB'
        self.network_path = 'QualiSB'

        #self.dv_switch_name = 'dvSwitch-SergiiT'
        self.dv_switch_name = 'dvSwitch'
        #self.dv_port_group_name = 'aa-dvPortGroup3B'
        self.dv_port_group_name = 'dvPortGroup'
        self.standard_network_name = "Anetwork"

        try:
            self.py_vmomi_service = pyVmomiService(SmartConnect, Disconnect)
            self.credentials = TestCredentials()
            self.resource_connection_details_retriever = Mock()
            self.resource_connection_details_retriever.connection_details = Mock(
                return_value=VCenterConnectionDetails(self.credentials.host,
                                                      self.credentials.username,
                                                      self.credentials.password))

            self.synchronous_task_waiter = SynchronousTaskWaiter()
            self.pg_name_generator = DvPortGroupNameGenerator
            self.vnic_to_network_mapper = VnicToNetworkMapper(self.pg_name_generator)

            self.configurer = VirtualMachinePortGroupConfigurer(self.py_vmomi_service,
                                                                self.synchronous_task_waiter,
                                                                self.vnic_to_network_mapper,
                                                                VNicService())
        except:
            print "Infrastructure not available - pretty OK or UnitTesting environment"
    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)
예제 #10
0
 def _get_connection_details(session, password, user, address):
     password = session.DecryptPassword(password).Value
     return VCenterConnectionDetails(address, user, password)