예제 #1
0
 def wrapped_f(self):
     is_execute_func = True
     for func in args:
         if not func(self):
             is_execute_func = False
             break
     if is_execute_func:
         function(self)
     else:
         Environment.get_default_logger().debug(
             'Skipping ' + function.__name__ +
             ' due to depandancy failure.')
예제 #2
0
파일: depends.py 프로젝트: vmware/pyvcloud
 def wrapped_f(self):
     is_execute_func = True
     for func in args:
         if not func(self):
             is_execute_func = False
             break
     if is_execute_func:
         function(self)
     else:
         Environment.get_default_logger().debug(
             'Skipping ' + function.__name__ +
             ' due to depandancy failure.')
예제 #3
0
    def _template_upload_helper(self, org, catalog_name, template_name,
                                template_file_name):
        """Helper method to upload a template to a catalog in vCD.

        This method creates the catalog item and uploads the template file
        into the spool area(transfer folder) but it doesn't wait for the
        import of the template as catalog item to finish.

        :param pyvcloud.vcd.org.Org org: the organization which contains the
            catalog to which the templates will be uploaded to.
        :param str catalog_name: name of the catalog to which the template will
            be uploaded to.
        :param str template_name: name of the catalog item which represents the
            uploaded template
        :param str template_file_name: name of the local template file which
            will be uploaded.

        :raises: EntityNotFoundException: if the catalog is not found.
        :raises: InternalServerException: if template already exists in vCD.
        """
        bytes_uploaded = -1
        logger = Environment.get_default_logger()
        logger.debug('Uploading template : ' + template_name)
        bytes_uploaded = org.upload_ovf(catalog_name=catalog_name,
                                        file_name=template_file_name,
                                        item_name=template_name)
        self.assertNotEqual(bytes_uploaded, -1)
예제 #4
0
    def test_0000_setup(self):
        self._config = Environment.get_config()
        TestVappNat._logger = Environment.get_default_logger()
        TestVappNat._client = Environment.get_sys_admin_client()
        TestVappNat._runner = CliRunner()
        default_org = self._config['vcd']['default_org_name']
        self._login()
        TestVappNat._runner.invoke(org, ['use', default_org])

        vapp = Environment.get_test_vapp_with_network(TestVappNat._client)
        vapp.reload()
        task = vapp.connect_vapp_network_to_ovdc_network(
            network_name=TestVappNat._vapp_network_name,
            orgvdc_network_name=TestVappNat._org_vdc_network_name)
        result = TestVappNat._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        vm_resource = vapp.get_vm(TestVappNat._vm_name)
        vm = VM(TestVappNat._client, resource=vm_resource)
        task = vm.add_nic(NetworkAdapterType.E1000.value, True, True,
                          TestVappNat._vapp_network_name,
                          IpAddressMode.MANUAL.value,
                          TestVappNat._allocate_ip_address)
        result = TestVappNat._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
        list_vm_interface = vapp.list_vm_interface(
            TestVappNat._vapp_network_name)
        for vm_interface in list_vm_interface:
            TestVappNat._vm_id = str(vm_interface['Local_id'])
            TestVappNat._vm_nic_id = str(vm_interface['VmNicId'])
예제 #5
0
    def test_0000_setup(self):

        self._config = Environment.get_config()
        TestFirewallRule._logger = Environment.get_default_logger()
        TestFirewallRule._client = Environment.get_sys_admin_client()
        TestFirewallRule._runner = CliRunner()
        default_org = self._config['vcd']['default_org_name']
        TestFirewallRule._ext_nw = self._config['external_network']['name']
        self._login()
        TestFirewallRule._runner.invoke(org, ['use', default_org])
        result = TestFirewallRule._runner.invoke(
            gateway,
            args=[
                'services', 'firewall', 'create', TestFirewallRule.__name,
                '--name', TestFirewallRule.__firewall_rule_name, '--action',
                'accept', '--type', 'User', '--enabled', '--logging-enabled'
            ])
        self.assertEqual(0, result.exit_code)
        gateway_res = Environment.get_test_gateway(TestFirewallRule._client)
        gateway_obj = Gateway(
            TestFirewallRule._client, href=gateway_res.get('href'))
        firewall_rules = gateway_obj.get_firewall_rules()
        for rule in firewall_rules.firewallRules.firewallRule:
            if rule.name == TestFirewallRule.__firewall_rule_name:
                TestFirewallRule._rule_id = rule.id
                break
예제 #6
0
    def _template_upload_helper(self, org, catalog_name, template_name,
                                template_file_name):
        """Helper method to upload a template to a catalog in vCD.

        This method creates the catalog item and uploads the template file
        into the spool area(transfer folder) but it doesn't wait for the
        import of the template as catalog item to finish.

        :param pyvcloud.vcd.org.Org org: the organization which contains the
            catalog to which the templates will be uploaded to.
        :param str catalog_name: name of the catalog to which the template will
            be uploaded to.
        :param str template_name: name of the catalog item which represents the
            uploaded template
        :param str template_file_name: name of the local template file which
            will be uploaded.

        :raises: EntityNotFoundException: if the catalog is not found.
        :raises: InternalServerException: if template already exists in vCD.
        """
        bytes_uploaded = -1
        logger = Environment.get_default_logger()
        logger.debug('Uploading template : ' + template_name)
        bytes_uploaded = org.upload_ovf(
            catalog_name=catalog_name,
            file_name=template_file_name,
            item_name=template_name)
        self.assertNotEqual(bytes_uploaded, -1)
예제 #7
0
    def test_0070_update_catalog(self):
        """Test the method org.update_catalog().

        Update the name and description of the catalog created in
        test_0000_setup. Revert the changes madeto the catalog after we verify
        that the operation is successful.

        This test passes if the catalog updation operation succeeds without
        raising any errors.
        """
        logger = Environment.get_default_logger()
        org = Environment.get_test_org(TestCatalog._client)

        catalog_name = TestCatalog._test_catalog_name
        catalog_description = TestCatalog._test_catalog_description
        new_name = TestCatalog._test_catalog_updated_name
        new_description = TestCatalog._test_catalog_updated_description

        logger.debug('Changing catalog:' + catalog_name + ' \'name\' to ' +
                     new_name + ', and \'description\' to ' + new_description)
        updated_catalog_resource = org.update_catalog(catalog_name, new_name,
                                                      new_description)

        self.assertEqual(updated_catalog_resource.get('name'), new_name)
        self.assertEqual(updated_catalog_resource.Description.text,
                         new_description)

        logger.debug('Changing catalog:' + new_name + ' \'name\' back to ' +
                     catalog_name + ',and \'description\' back to ' +
                     catalog_description)
        org.reload()
        org.update_catalog(new_name, catalog_name, catalog_description)
예제 #8
0
    def test_0110_create_vapp_network(self):
        """Test the method vapp.create_vapp_network().

        This test passes if the vApp network creation is successful.
        """
        logger = Environment.get_default_logger()
        vapp_name = TestVApp._customized_vapp_name
        vapp = Environment.get_vapp_in_test_vdc(client=TestVApp._client,
                                                vapp_name=vapp_name)
        logger.debug('Creating a vApp network in ' +
                     TestVApp._customized_vapp_name)
        task = vapp.create_vapp_network(
            TestVApp._vapp_network_name, TestVApp._vapp_network_cidr,
            TestVApp._vapp_network_description, TestVApp._vapp_network_dns1,
            TestVApp._vapp_network_dns2, TestVApp._vapp_network_dns_suffix,
            [TestVApp._vapp_network_ip_range])
        result = TestVApp._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
        # Verification
        vapp.reload()
        vapp_resource = vapp.get_resource()
        is_network_found = False
        for network_config in vapp_resource.NetworkConfigSection.NetworkConfig:
            if (network_config.get('networkName') ==
                    TestVApp._vapp_network_name):
                is_network_found = True
        self.assertTrue(is_network_found)
예제 #9
0
    def test_0070_vm_snapshot_operations(self):
        """Test the method related to snapshot operations in vm.py.

        This test passes if all the snapshot operations are successful.
        """
        logger = Environment.get_default_logger()
        vm_name = TestVM._test_vapp_first_vm_name
        vm = VM(TestVM._client, href=TestVM._test_vapp_first_vm_href)

        # VM.snapshot_create()
        logger.debug('Creating snapshot of vm ' + vm_name)
        task = vm.snapshot_create(memory=False, quiesce=False)
        result = TestVM._client.get_task_monitor().wait_for_success(task=task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        # VM.snapshot_revert_to_current
        logger.debug('Reverting vm ' + vm_name + ' to it\'s snapshot.')
        vm.reload()
        task = vm.snapshot_revert_to_current()
        result = TestVM._client.get_task_monitor().wait_for_success(task=task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        # VM.snapshot_remove_all()
        logger.debug('Removing all snapshots of vm ' + vm_name)
        vm.reload()
        task = vm.snapshot_remove_all()
        result = TestVM._client.get_task_monitor().wait_for_success(task=task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
예제 #10
0
    def setUp(self):
        """Load configuration and create a click runner to invoke CLI."""
        self._config = Environment.get_config()
        self._logger = Environment.get_default_logger()

        self._runner = CliRunner()
        self._login()
예제 #11
0
 def test_0040_enable_disable_vdc(self):
     """Test the method VDC.enable_vdc().
     First disable the vdc, try to re-disable it (which should fail). Next,
     enable the vdc back, and then try to re-enable the vdc (which should
     fail).
     This test passes if the state of vdc matches our expectation after each
     operation.
     """
     logger = Environment.get_default_logger()
     vdc = VDC(TestOrgVDC._client, href=TestOrgVDC._new_vdc_href)
     # vdc should be in enabled state after the previous tests.
     vdc.enable_vdc(enable=False)
     logger.debug('Disabled vdc ' + TestOrgVDC._new_vdc_name + '.')
     try:
         logger.debug('Trying to again disable vdc ' +
                      TestOrgVDC._new_vdc_name + '.')
         vdc.enable_vdc(enable=False)
         self.fail('Should not be able to disable vdc ' +
                   TestOrgVDC._new_vdc_href)
     except OperationNotSupportedException as e:
         pass
     vdc.enable_vdc(enable=True)
     logger.debug('Enabled vdc ' + TestOrgVDC._new_vdc_name + '.')
     try:
         logger.debug('Trying to again enable vdc ' +
                      TestOrgVDC._new_vdc_name + '.')
         vdc.enable_vdc(enable=True)
         self.fail('Should not be able to enable vdc ' +
                   TestOrgVDC._new_vdc_href)
     except OperationNotSupportedException as e:
         pass
예제 #12
0
    def test_0010_vm_setup(self):
        """Setup the vms required for the other tests in this module.

        Create a vApp with just one vm as per the configuration stated above.

        This test passes if the vApp and vm hrefs are not None.
        """
        logger = Environment.get_default_logger()
        TestPVDC._org_client = Environment.get_client_in_default_org(
            TestPVDC._test_runner_role)
        vdc = Environment.get_test_vdc(TestPVDC._org_client)

        logger.debug('Creating vApp ' + TestPVDC._test_vapp_name + '.')
        TestPVDC._test_vapp_href = create_customized_vapp_from_template(
            client=TestPVDC._org_client,
            vdc=vdc,
            name=TestPVDC._test_vapp_name,
            catalog_name=Environment.get_default_catalog_name(),
            template_name=Environment.get_default_template_name(),
            memory_size=TestPVDC._test_vapp_first_vm_memory_size,
            num_cpu=TestPVDC._test_vapp_first_vm_num_cpu,
            disk_size=TestPVDC._test_vapp_first_vm_first_disk_size,
            vm_name=TestPVDC._test_vapp_first_vm_name,
            nw_adapter_type=TestPVDC._test_vapp_first_vm_network_adapter_type)

        self.assertIsNotNone(TestPVDC._test_vapp_href)

        vapp = VApp(TestPVDC._org_client, href=TestPVDC._test_vapp_href)
        vm_resource = vapp.get_vm(TestPVDC._test_vapp_first_vm_name)
        TestPVDC._test_vapp_first_vm_href = vm_resource.get('href')

        self.assertIsNotNone(TestPVDC._test_vapp_first_vm_href)
예제 #13
0
    def _template_import_monitor(self, client, org, catalog_name,
                                 template_name):
        """Helper method to block until a template is imported in vCD.

        :param client: An object of :class: `pyvcloud.vcd.client.Client` that
            would be used to make ReST calls to vCD.
        :param org: An object of :class:`lxml.objectify.StringElement`that
            describes the organization, which the templates is being imported
            into.
        :param catalog_name: (str): Name of the catalog to which the template
            is being imported.
        :param template_name: (str): Name of the catalog item which represents
            the uploaded template.

        :return: Nothing

        :raises: EntityNotFoundException: If the catalog/item is not found.
        """
        logger = Environment.get_default_logger()
        logger.debug('Importing template : ' + template_name + ' in vCD')
        # wait for the catalog item import to finish in vCD
        catalog_item_resource = org.get_catalog_item(catalog_name,
                                                     template_name)
        template_resource = client.get_resource(
            catalog_item_resource.Entity.get('href'))
        client.get_task_monitor().wait_for_success(
            task=template_resource.Tasks.Task[0])
예제 #14
0
    def test_0000_setup(self):
        """Load configuration and create a click runner to invoke CLI."""
        self._config = Environment.get_config()
        GatewayTest._logger = Environment.get_default_logger()

        GatewayTest._runner = CliRunner()
        default_org = self._config['vcd']['default_org_name']
        self._login()
        GatewayTest._runner.invoke(org, ['use', default_org])
        GatewayTest._api_version = self._config['vcd']['api_version']
        GatewayTest._ext_network_name = self._get_first_external_network()

        self.client = Environment.get_sys_admin_client()
        platform = Platform(self.client)
        ext_net_resource = platform.get_external_network(
            GatewayTest._ext_network_name)

        self.assertTrue(len(ext_net_resource) > 0)

        ip_scopes = ext_net_resource.xpath(
            'vcloud:Configuration/vcloud:IpScopes/vcloud:IpScope',
            namespaces=NSMAP)
        first_ipscope = ip_scopes[0]
        GatewayTest._gateway_ip = first_ipscope.Gateway.text
        prefix_len = netmask_to_cidr_prefix_len(GatewayTest._gateway_ip,
                                                first_ipscope.Netmask.text)
        GatewayTest._subnet_addr = GatewayTest._gateway_ip + '/' + str(
            prefix_len)
예제 #15
0
    def _create_customized_vapp_from_template(self, client, vdc):
        """Helper method to create a customized vApp from template.

        :param pyvcloud.vcd.client.Client client: a client that would be used
            to make ReST calls to vCD.
        :param pyvcloud.vcd.vcd.VDC vdc: the vdc in which the vApp will be
            created.

        :return: href of the created vApp.

        :rtype: str
        """
        logger = Environment.get_default_logger()
        logger.debug('Creating customized vApp.')
        vapp_sparse_resource = vdc.instantiate_vapp(
            name=TestVApp._customized_vapp_name,
            catalog=Environment.get_default_catalog_name(),
            template=Environment.get_default_template_name(),
            description=TestVApp._customized_vapp_description,
            deploy=True,
            power_on=True,
            accept_all_eulas=True,
            memory=TestVApp._customized_vapp_memory_size,
            cpu=TestVApp._customized_vapp_num_cpu,
            disk_size=TestVApp._customized_vapp_disk_size,
            vm_name=TestVApp._customized_vapp_vm_name,
            hostname=TestVApp._customized_vapp_vm_hostname,
            network_adapter_type=TestVApp.
            _customized_vapp_vm_network_adapter_type)

        task = client.get_task_monitor().wait_for_success(
            vapp_sparse_resource.Tasks.Task[0])
        self.assertEqual(task.get('status'), TaskStatus.SUCCESS.value)

        return vapp_sparse_resource.get('href')
예제 #16
0
    def test_0060_vapp_network_connection(self):
        """Test vapp.connect/disconnect_org_vdc_network().

        This test passes if the connect and disconnect to orgvdc network
        operations are successful.
        """
        logger = Environment.get_default_logger()

        network_name = Environment.get_default_orgvdc_network_name()

        vapp_name = TestVApp._customized_vapp_name
        vapp = Environment.get_vapp_in_test_vdc(
            client=TestVApp._client, vapp_name=vapp_name)

        logger.debug('Connecting vApp ' + vapp_name + ' to orgvdc network ' +
                     network_name)
        task = vapp.connect_org_vdc_network(network_name)
        result = TestVApp._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        logger.debug('Disconnecting vApp ' + vapp_name +
                     ' to orgvdc network ' + network_name)
        vapp.reload()
        task = vapp.disconnect_org_vdc_network(network_name)
        result = TestVApp._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
예제 #17
0
    def test_0080_update_service(self):
        """Test the method APIExtension.update_extension().

        This test passes if the routing key and exchange after execution of the
        method matches the respective test strings.
        """
        logger = Environment.get_default_logger()
        api_extension = APIExtension(TestApiExtension._client)
        ext_name = TestApiExtension._service_name
        ext_namespace = TestApiExtension._service1_namespace

        logger.debug('Updating service (name:' + ext_name + ', namespace:' +
                     ext_namespace + ').')

        test_routing_key = 'testroutingkey'
        test_exchange = 'testexchange'
        href = api_extension.update_extension(name=ext_name,
                                              namespace=ext_namespace,
                                              routing_key=test_routing_key,
                                              exchange=test_exchange)
        self.assertEqual(href, TestApiExtension._service1_href)

        ext_info = api_extension.get_extension_info(ext_name,
                                                    namespace=ext_namespace)
        self.assertEqual(ext_info['routingKey'], test_routing_key)
        self.assertEqual(ext_info['exchange'], test_exchange)
예제 #18
0
    def test_0057_vapp_network_disconnect(self):
        """Test vapp.disconnect_org_vdc_network().

        This test passes if the connect and disconnect to orgvdc network
           operations are successful.
        """
        try:
            logger = Environment.get_default_logger()
            client = Environment.get_client_in_default_org(
                CommonRoles.ORGANIZATION_ADMINISTRATOR)

            network_name = Environment.get_default_orgvdc_network_name()

            vapp_name = TestVApp._customized_vapp_name
            vapp = Environment.get_vapp_in_test_vdc(client=client,
                                                    vapp_name=vapp_name)

            logger.debug('Disconnecting vApp ' + vapp_name + ' to orgvdc network ' +
                  network_name)
            vapp.reload()
            task = vapp.disconnect_org_vdc_network(network_name)
            result = client.get_task_monitor().wait_for_success(task)
            self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
        finally:
            client.logout()
예제 #19
0
    def test_0060_enable_disable_service(self):
        """Test the method APIExtension.enable_extension().

        This test passes if the href returned after each execution of the
        method matches the service href.
        """
        logger = Environment.get_default_logger()
        api_extension = APIExtension(TestApiExtension._client)

        logger.debug('Disabling service (name:' +
                     TestApiExtension._service_name + ', namespace:' +
                     TestApiExtension._service1_namespace + ').')
        href = api_extension.enable_extension(
            name=TestApiExtension._service_name,
            namespace=TestApiExtension._service1_namespace,
            enabled=False)
        self.assertEqual(href, TestApiExtension._service1_href)

        logger.debug('Re-enabling service (name:' +
                     TestApiExtension._service_name + ', namespace:' +
                     TestApiExtension._service1_namespace + ').')
        href = api_extension.enable_extension(
            name=TestApiExtension._service_name,
            namespace=TestApiExtension._service1_namespace,
            enabled=True)
        self.assertEqual(href, TestApiExtension._service1_href)
예제 #20
0
    def test_007_register_service_right(self):
        """Test the method APIExtension.add_service_right().

        This test passes if the right-name returned after execution of the
        method matches the expected right-name.
        """
        logger = Environment.get_default_logger()
        api_extension = APIExtension(TestApiExtension._client)

        # Create a new right for CSE RBAC
        logger.debug('Registering service right(name:' +
                     TestApiExtension._right_name + ', description:' +
                     TestApiExtension._description + ', category:' +
                     TestApiExtension._category + ').')
        register_right = api_extension.add_service_right(
            right_name=TestApiExtension._right_name,
            service_name=TestApiExtension._service_name,
            namespace=TestApiExtension._service1_namespace,
            description=TestApiExtension._description,
            category=TestApiExtension._category,
            bundle_key=TestApiExtension._bundle_key)

        expected_right_name = '{' + TestApiExtension._service1_namespace +\
                              '}:' + TestApiExtension._right_name
        registered_right_name = register_right.get('name')
        self.assertEqual(expected_right_name, registered_right_name)
예제 #21
0
    def test_0061_detach_port_group(self):
        """Detach a portgroup from an external network
       This test passes if the portgroup from another vCenter is removed
       from external network successfully.
       """
        if TestExtNet._vc2_host_ip is None or TestExtNet._vc2_host_ip == '':
            return
        logger = Environment.get_default_logger()
        platform = Platform(TestExtNet._sys_admin_client)
        vc_name = TestExtNet._config['vc2']['vcenter_host_name']
        port_group_helper = PortgroupHelper(TestExtNet._sys_admin_client)
        pg_name = port_group_helper.get_ext_net_portgroup_name(
            vc_name, self._name)

        ext_net = self._get_ext_net(platform).detach_port_group(
            vc_name, pg_name)
        task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0]
        TestExtNet._sys_admin_client.get_task_monitor().wait_for_success(
            task=task)
        logger.debug('Detach a portgroup from an external network' +
                     TestExtNet._name)
        ext_net = platform.get_external_network(self._name)
        self.assertIsNotNone(ext_net)
        vc_record = platform.get_vcenter(vc_name)
        vc_href = vc_record.get('href')
        vim_port_group_ref = ext_net.VimPortGroupRef
        vc_href_found = False

        if vim_port_group_ref.VimServerRef.get('href') == vc_href:
            vc_href_found = True
        self.assertFalse(vc_href_found)
예제 #22
0
    def test_0010_update(self):
        """Test the method Platform.update_external_network()

        Update name and description of the external network created by setup.
        Verifies name and description after update completes. Reset the name
        and description to original.

        This test passes if name and description are updated successfully.
        """
        logger = Environment.get_default_logger()
        platform = Platform(TestExtNet._sys_admin_client)
        new_name = 'updated_' + TestExtNet._name
        new_description = 'Updated ' + TestExtNet._description

        ext_net = platform.update_external_network(TestExtNet._name, new_name,
                                                   new_description)

        task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0]
        TestExtNet._sys_admin_client.get_task_monitor().wait_for_success(
            task=task)
        logger.debug('Updated external network ' + TestExtNet._name + '.')

        ext_net = platform.get_external_network(new_name)
        self.assertIsNotNone(ext_net)
        self.assertEqual(new_description,
                         ext_net['{' + NSMAP['vcloud'] + '}Description'].text)

        # Reset the name and description to original
        ext_net = platform.update_external_network(new_name, self._name,
                                                   self._description)
        task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0]
        TestExtNet._sys_admin_client.get_task_monitor().wait_for_success(
            task=task)
예제 #23
0
    def test_0055_delete_ip_range(self):
        """Test the method externalNetwork.delete_ip_range()
       Delete ip range of a subnet in external network
       This test passes if the ip range for a subnet is
       deleted successfully.
       """
        logger = Environment.get_default_logger()
        platform = Platform(TestExtNet._sys_admin_client)
        ext_net = self._get_ext_net(platform).delete_ip_range(
            TestExtNet._gateway2, [TestExtNet._ip_range4])

        task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0]
        TestExtNet._sys_admin_client.get_task_monitor().wait_for_success(
            task=task)
        logger.debug('Deleted ip-range of a subnet in external network' +
                     TestExtNet._name + '.')

        ext_net = platform.get_external_network(self._name)
        self.assertIsNotNone(ext_net)
        config = ext_net['{' + NSMAP['vcloud'] + '}Configuration']
        ip_scope = config.IpScopes.IpScope
        for scope in ip_scope:
            if scope.Gateway == TestExtNet._gateway2:
                ip_scope = scope
                break
        self.assertIsNotNone(ip_scope)
        self.assertFalse(
            self.__validate_ip_range(ip_scope, TestExtNet._ip_range4))
예제 #24
0
    def test_0060_attach_port_group(self):
        """Attach a portgroup to an external network
       This test passes if the portgroup from another vCenter is added
       to external network successfully.
       """
        if TestExtNet._vc2_host_ip is None or TestExtNet._vc2_host_ip == '':
            return
        logger = Environment.get_default_logger()
        platform = Platform(TestExtNet._sys_admin_client)
        vc_name = TestExtNet._config['vc2']['vcenter_host_name']
        portgrouphelper = PortgroupHelper(TestExtNet._sys_admin_client)
        pg_name = portgrouphelper.get_available_portgroup_name(
            vc_name, TestExtNet._portgroupType)

        ext_net = self._get_ext_net(platform).attach_port_group(
            vc_name, pg_name)
        task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0]
        TestExtNet._sys_admin_client.get_task_monitor().wait_for_success(
            task=task)
        logger.debug('Attach a portgroup to an external network' +
                     TestExtNet._name + '.')
        ext_net = platform.get_external_network(self._name)
        self.assertIsNotNone(ext_net)
        vc_record = platform.get_vcenter(vc_name)
        vc_href = vc_record.get('href')
        vim_port_group_refs = \
            ext_net['{' + NSMAP['vmext'] + '}VimPortGroupRefs']
        vc_href_found = False
        for vim_obj_ref in vim_port_group_refs.VimObjectRef:
            if vim_obj_ref.VimServerRef.get('href') == vc_href:
                vc_href_found = True
                break
        self.assertTrue(vc_href_found)
예제 #25
0
    def test_0030_enable_subnet(self):
        """Test the method externalNetwork.enable_subnet()

        Enable subnet of external network

        This test passes if subnet is enabled successfully.
        """
        logger = Environment.get_default_logger()
        platform = Platform(TestExtNet._sys_admin_client)

        ext_net = self._get_ext_net(platform).enable_subnet(
            TestExtNet._gateway2, True)

        task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0]
        TestExtNet._sys_admin_client.get_task_monitor().wait_for_success(
            task=task)
        logger.debug('Enabled subnet of external network ' + TestExtNet._name +
                     '.')

        ext_net = platform.get_external_network(self._name)
        self.assertIsNotNone(ext_net)
        config = ext_net['{' + NSMAP['vcloud'] + '}Configuration']
        ip_scope = config.IpScopes.IpScope
        for scope in ip_scope:
            if scope.Gateway == TestExtNet._gateway2:
                ip_scope = scope
                break
        self.assertIsNotNone(ip_scope)
        self.assertEqual(ip_scope.IsEnabled, True)
예제 #26
0
    def test_0020_add_subnet(self):
        """Test the method externalNetwork.add_subnet()

        Add subnet to the existing external network

        This test passes if subnet is added successfully.
        """
        logger = Environment.get_default_logger()
        platform = Platform(TestExtNet._sys_admin_client)
        ext_net_resource = platform.get_external_network(self._name)
        extnet_obj = ExternalNetwork(TestExtNet._sys_admin_client,
                                     resource=ext_net_resource)

        ext_net = extnet_obj.add_subnet(self._name, TestExtNet._gateway2,
                                        TestExtNet._netmask,
                                        [TestExtNet._ip_range2],
                                        TestExtNet._dns1, TestExtNet._dns2,
                                        TestExtNet._dns_suffix)

        task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0]
        TestExtNet._sys_admin_client.get_task_monitor().wait_for_success(
            task=task)
        logger.debug('Added subnet to external network ' + TestExtNet._name +
                     '.')

        ext_net = platform.get_external_network(self._name)
        self.assertIsNotNone(ext_net)
        config = ext_net['{' + NSMAP['vcloud'] + '}Configuration']
        new_subnet = config.IpScopes.IpScope[-1]
        self.assertEqual(TestExtNet._gateway2, new_subnet.Gateway.text)
        self.assertEqual(TestExtNet._netmask, new_subnet.Netmask.text)
예제 #27
0
    def test_0040_vapp_power_options(self):
        """Test the method related to power operations in vapp.py.

        This test passes if all the power operations are successful.
        """
        logger = Environment.get_default_logger()
        vapp_name = TestVApp._customized_vapp_name
        vapp = Environment.get_vapp_in_test_vdc(client=TestVApp._client,
                                                vapp_name=vapp_name)

        # make sure the vApp is powered on before running tests
        self._power_on_vapp_if_possible(TestVApp._client, vapp)

        logger.debug('Un-deploying vApp ' + vapp_name)
        vapp.reload()
        task = vapp.undeploy()
        result = TestVApp._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        logger.debug('Deploying vApp ' + vapp_name)
        vapp.reload()
        task = vapp.deploy(power_on=False)
        result = TestVApp._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        logger.debug('Powering on vApp ' + vapp_name)
        vapp.reload()
        task = vapp.power_on()
        result = TestVApp._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        logger.debug('Reseting (power) vApp ' + vapp_name)
        vapp.reload()
        task = vapp.power_reset()
        result = TestVApp._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        logger.debug('Powering off vApp ' + vapp_name)
        vapp.reload()
        task = vapp.power_off()
        result = TestVApp._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        logger.debug('Powering back on vApp ' + vapp_name)
        vapp.reload()
        task = vapp.power_on()
        result = TestVApp._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        logger.debug('Rebooting (power) vApp ' + vapp_name)
        vapp.reload()
        task = vapp.reboot()
        result = TestVApp._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        logger.debug('Shutting down vApp ' + vapp_name)
        vapp.reload()
        task = vapp.shutdown()
        result = TestVApp._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
예제 #28
0
    def test_0060_vapp_network_connection(self):
        """Test vapp.connect/disconnect_org_vdc_network().

        This test passes if the connect and disconnect to orgvdc network
        operations are successful.
        """
        logger = Environment.get_default_logger()

        network_name = Environment.get_default_orgvdc_network_name()

        vapp_name = TestVApp._customized_vapp_name
        vapp = Environment.get_vapp_in_test_vdc(client=TestVApp._client,
                                                vapp_name=vapp_name)

        logger.debug('Connecting vApp ' + vapp_name + ' to orgvdc network ' +
                     network_name)
        task = vapp.connect_org_vdc_network(network_name)
        result = TestVApp._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        logger.debug('Disconnecting vApp ' + vapp_name +
                     ' to orgvdc network ' + network_name)
        vapp.reload()
        task = vapp.disconnect_org_vdc_network(network_name)
        result = TestVApp._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
예제 #29
0
    def test_0010_update(self):
        """Test the method Platform.update_external_network()

        Update name and description of the external network created by setup.
        Verifies name and description after update completes. Reset the name
        and description to original.

        This test passes if name and description are updated successfully.
        """
        logger = Environment.get_default_logger()
        platform = Platform(TestExtNet._sys_admin_client)
        new_name = 'updated_' + TestExtNet._name
        new_description = 'Updated ' + TestExtNet._description

        ext_net = platform.update_external_network(TestExtNet._name, new_name,
                                                   new_description)

        task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0]
        TestExtNet._sys_admin_client.get_task_monitor().wait_for_success(
            task=task)
        logger.debug('Updated external network ' + TestExtNet._name + '.')

        ext_net = platform.get_external_network(new_name)
        self.assertIsNotNone(ext_net)
        self.assertEqual(new_description,
                         ext_net['{' + NSMAP['vcloud'] + '}Description'].text)

        # Reset the name and description to original
        ext_net = platform.update_external_network(new_name, self._name,
                                                   self._description)
        task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0]
        TestExtNet._sys_admin_client.get_task_monitor().wait_for_success(
            task=task)
예제 #30
0
    def test_0000_setup(self):
        """Load configuration and create a click runner to invoke CLI."""
        VAppTest._config = Environment.get_config()
        VAppTest._logger = Environment.get_default_logger()
        VAppTest._client = Environment.get_client_in_default_org(
            CommonRoles.ORGANIZATION_ADMINISTRATOR)
        VAppTest._sys_admin_client = Environment.get_sys_admin_client()

        VAppTest._runner = CliRunner()
        default_org = VAppTest._config['vcd']['default_org_name']
        VAppTest._default_org = default_org
        VAppTest._login(self)
        VAppTest._runner.invoke(org, ['use', default_org])
        VAppTest._test_vdc = Environment.get_test_vdc(VAppTest._client)
        VAppTest._test_vapp = create_vapp_from_template(
            VAppTest._client,
            VAppTest._test_vdc,
            VAppTest._test_vapp_name,
            VAppTest._config['vcd']['default_catalog_name'],
            VAppTest._config['vcd']['default_template_file_name'],
            power_on=False,
            deploy=False)
        VAppTest._catalog_name = VAppTest._config['vcd'][
            'default_catalog_name']
        VAppTest._sys_admin_client = Environment.get_sys_admin_client()
        VAppTest._pvdc_name = Environment.get_test_pvdc_name()
        default_ovdc = VAppTest._config['vcd']['default_ovdc_name']
        VAppTest._default_ovdc = default_ovdc
예제 #31
0
    def test_0010_vm_setup(self):
        """Setup the vms required for the other tests in this module.

        Create a vApp with just one vm as per the configuration stated above.

        This test passes if the vApp and vm hrefs are not None.
        """
        logger = Environment.get_default_logger()
        TestPVDC._org_client = Environment.get_client_in_default_org(
            TestPVDC._test_runner_role)
        vdc = Environment.get_test_vdc(TestPVDC._org_client)

        logger.debug('Creating vApp ' + TestPVDC._test_vapp_name + '.')
        TestPVDC._test_vapp_href = create_customized_vapp_from_template(
            client=TestPVDC._org_client,
            vdc=vdc,
            name=TestPVDC._test_vapp_name,
            catalog_name=Environment.get_default_catalog_name(),
            template_name=Environment.get_default_template_name(),
            memory_size=TestPVDC._test_vapp_first_vm_memory_size,
            num_cpu=TestPVDC._test_vapp_first_vm_num_cpu,
            disk_size=TestPVDC._test_vapp_first_vm_first_disk_size,
            vm_name=TestPVDC._test_vapp_first_vm_name,
            nw_adapter_type=TestPVDC._test_vapp_first_vm_network_adapter_type)

        self.assertIsNotNone(TestPVDC._test_vapp_href)

        vapp = VApp(TestPVDC._org_client, href=TestPVDC._test_vapp_href)
        vm_resource = vapp.get_vm(TestPVDC._test_vapp_first_vm_name)
        TestPVDC._test_vapp_first_vm_href = vm_resource.get('href')

        self.assertIsNotNone(TestPVDC._test_vapp_first_vm_href)
예제 #32
0
    def _template_upload_helper(self, org, catalog_name, template_name,
                                template_file_name):
        """Helper method to upload a template to a catalog in vCD.

        This method creates the catalog item and uploads the template file
        into the spool area(transfer folder) but it doesn't wait for the
        import of the template as catalog item to finish.

        :param org: An object of :class:`lxml.objectify.StringElement`that
            describes the organization which contains the catalog to which
            the templates will be uploaded to.
        :param catalog_name: (str): Name of the catalog to which the template
            will be uploaded to.
        :param template_name: (str): Name of the catalog item which represents
            the uploaded template
        :param template_file_name: (str): Name of the local template file which
            will be uploaded.

        :return: Nothing

        :raises: EntityNotFoundException: If the catalog is not found.
        :raises: InternalServerException: If template already exists in vCD.
        """
        bytes_uploaded = -1
        logger = Environment.get_default_logger()
        logger.debug('Uploading template : ' + template_name)
        bytes_uploaded = org.upload_ovf(catalog_name=catalog_name,
                                        file_name=template_file_name,
                                        item_name=template_name)
        self.assertNotEqual(bytes_uploaded, -1)
예제 #33
0
    def test_0160_move_to(self):
        org = Environment.get_test_org(TestVApp._client)
        target_vdc = org.get_vdc(TestVApp._ovdc_name)
        logger = Environment.get_default_logger()
        vapp = Environment.get_vapp_in_test_vdc(
            client=TestVApp._sys_admin_client,
            vapp_name=TestVApp._customized_vapp_name)

        logger.debug('Move vApp ' + TestVApp._customized_vapp_name)
        task = vapp.move_to(target_vdc.get('href'))
        result = TestVApp._sys_admin_client.get_task_monitor(
        ).wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        target_vdc = org.get_vdc(TestVApp._ovdc_name)
        target_vdc_obj = VDC(TestVApp._sys_admin_client,
                             href=target_vdc.get('href'))
        vapp_resource = target_vdc_obj.get_vapp(TestVApp._customized_vapp_name)
        vapp = VApp(TestVApp._sys_admin_client, resource=vapp_resource)

        target_vdc = Environment.get_test_vdc(TestVApp._client)
        logger.debug('Move back vApp ' + TestVApp._customized_vapp_name)
        task = vapp.move_to(target_vdc.href)
        result = TestVApp._sys_admin_client.get_task_monitor(
        ).wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
예제 #34
0
파일: vm_tests.py 프로젝트: vmware/pyvcloud
    def test_0070_vm_snapshot_operations(self):
        """Test the method related to snapshot operations in vm.py.

        This test passes if all the snapshot operations are successful.
        """
        logger = Environment.get_default_logger()
        vm_name = TestVM._test_vapp_first_vm_name
        vm = VM(TestVM._client, href=TestVM._test_vapp_first_vm_href)

        # VM.snapshot_create()
        logger.debug('Creating snapshot of vm ' + vm_name)
        task = vm.snapshot_create(memory=False, quiesce=False)
        result = TestVM._client.get_task_monitor().wait_for_success(task=task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        # VM.snapshot_revert_to_current
        logger.debug('Reverting vm ' + vm_name + ' to it\'s snapshot.')
        vm.reload()
        task = vm.snapshot_revert_to_current()
        result = TestVM._client.get_task_monitor().wait_for_success(task=task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        # VM.snapshot_remove_all()
        logger.debug('Removing all snapshots of vm ' + vm_name)
        vm.reload()
        task = vm.snapshot_remove_all()
        result = TestVM._client.get_task_monitor().wait_for_success(task=task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
예제 #35
0
    def test_0000_setup(self):

        self._config = Environment.get_config()
        TestFirewallRule._logger = Environment.get_default_logger()
        TestFirewallRule._client = Environment.get_sys_admin_client()
        TestFirewallRule._runner = CliRunner()
        default_org = self._config['vcd']['default_org_name']
        TestFirewallRule._ext_nw = self._config['external_network']['name']
        self._login()
        TestFirewallRule._runner.invoke(org, ['use', default_org])
        result = TestFirewallRule._runner.invoke(
            gateway,
            args=[
                'services', 'firewall', 'create', TestFirewallRule.__name,
                '--name', TestFirewallRule.__firewall_rule_name, '--action',
                'accept', '--type', 'User', '--enabled', '--logging-enabled'
            ])
        self.assertEqual(0, result.exit_code)
        gateway_res = Environment.get_test_gateway(TestFirewallRule._client)
        gateway_obj = Gateway(TestFirewallRule._client,
                              href=gateway_res.get('href'))
        firewall_rules = gateway_obj.get_firewall_rules()
        for rule in firewall_rules.firewallRules.firewallRule:
            if rule.name == TestFirewallRule.__firewall_rule_name:
                TestFirewallRule._rule_id = rule.id
                break
예제 #36
0
    def test_007_register_service_right(self):
        """Test the method APIExtension.add_service_right().

        This test passes if the right-name returned after execution of the
        method matches the expected right-name.
        """
        logger = Environment.get_default_logger()
        api_extension = APIExtension(TestApiExtension._client)

        # Create a new right for CSE RBAC
        logger.debug('Registering service right(name:' +
                     TestApiExtension._right_name + ', description:' +
                     TestApiExtension._description + ', category:' +
                     TestApiExtension._category + ').')
        register_right = api_extension.add_service_right(
            right_name=TestApiExtension._right_name,
            service_name=TestApiExtension._service_name,
            namespace=TestApiExtension._service1_namespace,
            description=TestApiExtension._description,
            category=TestApiExtension._category,
            bundle_key=TestApiExtension._bundle_key)

        expected_right_name = '{' + TestApiExtension._service1_namespace +\
                              '}:' + TestApiExtension._right_name
        registered_right_name = register_right.get('name')
        self.assertEqual(expected_right_name, registered_right_name)
예제 #37
0
    def test_0040_enable_disable_vdc(self):
        """Test the method VDC.enable_vdc().

        First disable the vdc, try to re-disable it (which should fail). Next,
        enable the vdc back, and then try to re-enable the vdc (which should
        fail).

        This test passes if the state of vdc matches our expectation after each
        operation.
        """
        logger = Environment.get_default_logger()
        vdc = VDC(TestOrgVDC._client, href=TestOrgVDC._new_vdc_href)
        # vdc should be in enabled state after the previous tests.

        vdc.enable_vdc(enable=False)
        logger.debug('Disabled vdc ' + TestOrgVDC._new_vdc_name + '.')
        try:
            logger.debug('Trying to again disable vdc ' +
                         TestOrgVDC._new_vdc_name + '.')
            vdc.enable_vdc(enable=False)
            self.fail('Should not be able to disable vdc ' +
                      TestOrgVDC._new_vdc_href)
        except OperationNotSupportedException as e:
            pass

        vdc.enable_vdc(enable=True)
        logger.debug('Enabled vdc ' + TestOrgVDC._new_vdc_name + '.')
        try:
            logger.debug('Trying to again enable vdc ' +
                         TestOrgVDC._new_vdc_name + '.')
            vdc.enable_vdc(enable=True)
            self.fail('Should not be able to enable vdc ' +
                      TestOrgVDC._new_vdc_href)
        except OperationNotSupportedException as e:
            pass
예제 #38
0
    def test_0060_attach_port_group(self):
        """Attach a portgroup to an external network
       This test passes if the portgroup from another vCenter is added
       to external network successfully.
       """
        if TestExtNet._vc2_host_ip is None or TestExtNet._vc2_host_ip == '':
            return
        logger = Environment.get_default_logger()
        platform = Platform(TestExtNet._sys_admin_client)
        vc_name = TestExtNet._config['vc2']['vcenter_host_name']
        portgrouphelper = PortgroupHelper(TestExtNet._sys_admin_client)
        pg_name = portgrouphelper.get_available_portgroup_name(
            vc_name, TestExtNet._portgroupType)

        ext_net = self._get_ext_net(platform).attach_port_group(
            vc_name,
            pg_name)
        task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0]
        TestExtNet._sys_admin_client.get_task_monitor().wait_for_success(
            task=task)
        logger.debug(
            'Attach a portgroup to an external network'
            + TestExtNet._name + '.')
        ext_net = platform.get_external_network(self._name)
        self.assertIsNotNone(ext_net)
        vc_record = platform.get_vcenter(vc_name)
        vc_href = vc_record.get('href')
        vim_port_group_refs = \
            ext_net['{' + NSMAP['vmext'] + '}VimPortGroupRefs']
        vc_href_found = False
        for vim_obj_ref in vim_port_group_refs.VimObjectRef:
            if vim_obj_ref.VimServerRef.get('href') == vc_href:
                vc_href_found = True
                break
        self.assertTrue(vc_href_found)
예제 #39
0
    def test_0061_detach_port_group(self):
        """Detach a portgroup from an external network
       This test passes if the portgroup from another vCenter is removed
       from external network successfully.
       """
        if TestExtNet._vc2_host_ip is None or TestExtNet._vc2_host_ip == '':
            return
        logger = Environment.get_default_logger()
        platform = Platform(TestExtNet._sys_admin_client)
        vc_name = TestExtNet._config['vc2']['vcenter_host_name']
        port_group_helper = PortgroupHelper(TestExtNet._sys_admin_client)
        pg_name = port_group_helper.get_ext_net_portgroup_name(vc_name,
                                                               self._name)

        ext_net = self._get_ext_net(platform).detach_port_group(vc_name,
                                                                pg_name)
        task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0]
        TestExtNet._sys_admin_client.get_task_monitor().wait_for_success(
            task=task)
        logger.debug(
            'Detach a portgroup from an external network' + TestExtNet._name)
        ext_net = platform.get_external_network(self._name)
        self.assertIsNotNone(ext_net)
        vc_record = platform.get_vcenter(vc_name)
        vc_href = vc_record.get('href')
        vim_port_group_ref = ext_net.VimPortGroupRef
        vc_href_found = False

        if vim_port_group_ref.VimServerRef.get('href') == vc_href:
            vc_href_found = True
        self.assertFalse(vc_href_found)
예제 #40
0
    def test_0030_enable_subnet(self):
        """Test the method externalNetwork.enable_subnet()

        Enable subnet of external network

        This test passes if subnet is enabled successfully.
        """
        logger = Environment.get_default_logger()
        platform = Platform(TestExtNet._sys_admin_client)

        ext_net = self._get_ext_net(platform).enable_subnet(
            TestExtNet._gateway2, True)

        task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0]
        TestExtNet._sys_admin_client.get_task_monitor().wait_for_success(
            task=task)
        logger.debug(
            'Enabled subnet of external network ' + TestExtNet._name + '.')

        ext_net = platform.get_external_network(self._name)
        self.assertIsNotNone(ext_net)
        config = ext_net['{' + NSMAP['vcloud'] + '}Configuration']
        ip_scope = config.IpScopes.IpScope
        for scope in ip_scope:
            if scope.Gateway == TestExtNet._gateway2:
                ip_scope = scope
                break
        self.assertIsNotNone(ip_scope)
        self.assertEqual(ip_scope.IsEnabled, True)
예제 #41
0
    def test_0055_delete_ip_range(self):
        """Test the method externalNetwork.delete_ip_range()
       Delete ip range of a subnet in external network
       This test passes if the ip range for a subnet is
       deleted successfully.
       """
        logger = Environment.get_default_logger()
        platform = Platform(TestExtNet._sys_admin_client)
        ext_net = self._get_ext_net(platform).delete_ip_range(
            TestExtNet._gateway2,
            [TestExtNet._ip_range4])

        task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0]
        TestExtNet._sys_admin_client.get_task_monitor().wait_for_success(
            task=task)
        logger.debug(
            'Deleted ip-range of a subnet in external network'
            + TestExtNet._name + '.')

        ext_net = platform.get_external_network(self._name)
        self.assertIsNotNone(ext_net)
        config = ext_net['{' + NSMAP['vcloud'] + '}Configuration']
        ip_scope = config.IpScopes.IpScope
        for scope in ip_scope:
            if scope.Gateway == TestExtNet._gateway2:
                ip_scope = scope
                break
        self.assertIsNotNone(ip_scope)
        self.assertFalse(self.__validate_ip_range(ip_scope,
                                                  TestExtNet._ip_range4))
예제 #42
0
    def setUp(self):
        """Load configuration and create a click runner to invoke CLI."""
        self._config = Environment.get_config()
        self._logger = Environment.get_default_logger()

        self._runner = CliRunner()
        self._login()
예제 #43
0
    def test_0020_add_subnet(self):
        """Test the method externalNetwork.add_subnet()

        Add subnet to the existing external network

        This test passes if subnet is added successfully.
        """
        logger = Environment.get_default_logger()
        platform = Platform(TestExtNet._sys_admin_client)
        ext_net_resource = platform.get_external_network(self._name)
        extnet_obj = ExternalNetwork(TestExtNet._sys_admin_client,
                                     resource=ext_net_resource)

        ext_net = extnet_obj.add_subnet(self._name,
                                        TestExtNet._gateway2,
                                        TestExtNet._netmask,
                                        [TestExtNet._ip_range2],
                                        TestExtNet._dns1,
                                        TestExtNet._dns2,
                                        TestExtNet._dns_suffix)

        task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0]
        TestExtNet._sys_admin_client.get_task_monitor().wait_for_success(
            task=task)
        logger.debug(
            'Added subnet to external network ' + TestExtNet._name + '.')

        ext_net = platform.get_external_network(self._name)
        self.assertIsNotNone(ext_net)
        config = ext_net['{' + NSMAP['vcloud'] + '}Configuration']
        new_subnet = config.IpScopes.IpScope[-1]
        self.assertEqual(TestExtNet._gateway2, new_subnet.Gateway.text)
        self.assertEqual(TestExtNet._netmask, new_subnet.Netmask.text)
예제 #44
0
    def test_0080_update_service(self):
        """Test the method APIExtension.update_extension().

        This test passes if the routing key and exchange after execution of the
        method matches the respective test strings.
        """
        logger = Environment.get_default_logger()
        api_extension = APIExtension(TestApiExtension._client)
        ext_name = TestApiExtension._service_name
        ext_namespace = TestApiExtension._service1_namespace

        logger.debug('Updating service (name:' +
                     ext_name + ', namespace:' +
                     ext_namespace + ').')

        test_routing_key = 'testroutingkey'
        test_exchange = 'testexchange'
        href = api_extension.update_extension(
            name=ext_name,
            namespace=ext_namespace,
            routing_key=test_routing_key,
            exchange=test_exchange)
        self.assertEqual(href, TestApiExtension._service1_href)

        ext_info = api_extension.get_extension_info(ext_name,
                                                    namespace=ext_namespace)
        self.assertEqual(ext_info['routingKey'], test_routing_key)
        self.assertEqual(ext_info['exchange'], test_exchange)
예제 #45
0
    def test_0070_update_catalog(self):
        """Test the method org.update_catalog().

        Update the name and description of the catalog created in
        test_0000_setup. Revert the changes madeto the catalog after we verify
        that the operation is successful.

        This test passes if the catalog updation operation succeeds without
        raising any errors.
        """
        logger = Environment.get_default_logger()
        org = Environment.get_test_org(TestCatalog._client)

        catalog_name = TestCatalog._test_catalog_name
        catalog_description = TestCatalog._test_catalog_description
        new_name = TestCatalog._test_catalog_updated_name
        new_description = TestCatalog._test_catalog_updated_description

        logger.debug('Changing catalog:' + catalog_name + ' \'name\' to ' +
                     new_name + ', and \'description\' to ' + new_description)
        updated_catalog_resource = org.update_catalog(catalog_name, new_name,
                                                      new_description)

        self.assertEqual(updated_catalog_resource.get('name'), new_name)
        self.assertEqual(updated_catalog_resource.Description.text,
                         new_description)

        logger.debug('Changing catalog:' + new_name + ' \'name\' back to ' +
                     catalog_name + ',and \'description\' back to ' +
                     catalog_description)
        org.reload()
        org.update_catalog(new_name, catalog_name, catalog_description)
예제 #46
0
    def test_0060_enable_disable_service(self):
        """Test the method APIExtension.enable_extension().

        This test passes if the href returned after each execution of the
        method matches the service href.
        """
        logger = Environment.get_default_logger()
        api_extension = APIExtension(TestApiExtension._client)

        logger.debug('Disabling service (name:' +
                     TestApiExtension._service_name + ', namespace:' +
                     TestApiExtension._service1_namespace + ').')
        href = api_extension.enable_extension(
            name=TestApiExtension._service_name,
            namespace=TestApiExtension._service1_namespace,
            enabled=False)
        self.assertEqual(href, TestApiExtension._service1_href)

        logger.debug('Re-enabling service (name:' +
                     TestApiExtension._service_name + ', namespace:' +
                     TestApiExtension._service1_namespace + ').')
        href = api_extension.enable_extension(
            name=TestApiExtension._service_name,
            namespace=TestApiExtension._service1_namespace,
            enabled=True)
        self.assertEqual(href, TestApiExtension._service1_href)
예제 #47
0
    def test_0000_setup(self):
        """Setup the independent disks for the other tests in this module.

        Create three independent disks as per the configuration stated above.
        In case the disks exist, re-use them.

        This test passes if all the three disk ids are not None.
        """
        logger = Environment.get_default_logger()
        TestDisk._client = Environment.get_client_in_default_org(
            TestDisk._test_runner_role)
        vdc = Environment.get_test_vdc(TestDisk._client)

        # TODO(): Create a vApp for this test, so that attach and detach of
        # disk can be run as vapp author user instead of org admin
        disks = vdc.get_disks()
        for disk in disks:
            if TestDisk._idisk1_id is None and \
                    disk.get('name').lower() == self._idisk1_name:
                logger.debug('Reusing ' + TestDisk._idisk1_name)
                TestDisk._idisk1_id = disk.get('id')[16:]
            elif TestDisk._idisk2_id is None and \
                    disk.get('name').lower() == self._idisk2_name and \
                    str(disk.Description).lower() == \
                    self._idisk2_description.lower():
                logger.debug('Reusing ' + TestDisk._idisk2_name)
                TestDisk._idisk2_id = disk.get('id')[16:]
            elif TestDisk._idisk3_id is None and \
                    disk.get('name').lower() == self._idisk3_name:
                logger.debug('Reusing ' + TestDisk._idisk3_name)
                TestDisk._idisk3_id = disk.get('id')[16:]

        if TestDisk._idisk1_id is None:
            TestDisk._idisk1_id = self._create_disk_helper(
                client=TestDisk._client,
                vdc=vdc,
                disk_name=self._idisk1_name,
                disk_size=self._idisk1_size,
                disk_description=self._idisk1_description)

        if TestDisk._idisk2_id is None:
            TestDisk._idisk2_id = self._create_disk_helper(
                client=TestDisk._client,
                vdc=vdc,
                disk_name=self._idisk2_name,
                disk_size=self._idisk2_size,
                disk_description=self._idisk2_description)

        if TestDisk._idisk3_id is None:
            TestDisk._idisk3_id = self._create_disk_helper(
                client=TestDisk._client,
                vdc=vdc,
                disk_name=self._idisk3_name,
                disk_size=self._idisk3_size,
                disk_description=self._idisk3_description)

        self.assertIsNotNone(TestDisk._idisk1_id)
        self.assertIsNotNone(TestDisk._idisk2_id)
        self.assertIsNotNone(TestDisk._idisk3_id)
예제 #48
0
파일: vc_tests.py 프로젝트: vmware/pyvcloud
 def test_0020_get_vc(self):
     """Platform.get_vcenter finds a known vcenter."""
     logger = Environment.get_default_logger()
     platform = Platform(TestVC._client)
     vcenter = platform.get_vcenter(TestVC._vcenter_host_name)
     logger.debug('vCenter: name=%s, url=%s' %
                  (vcenter.get('name'), vcenter.Url.text))
     self.assertIsNotNone(vcenter)
예제 #49
0
파일: vc_tests.py 프로젝트: vmware/pyvcloud
 def test_0010_list_vc(self):
     """Platform.list_vcenters prints a list of virtual center servers."""
     logger = Environment.get_default_logger()
     platform = Platform(TestVC._client)
     vcenters = platform.list_vcenters()
     for vcenter in vcenters:
         logger.debug('vCenter found: %s' % vcenter.get('name'))
     self.assertTrue(len(vcenters) > 0)
예제 #50
0
    def setUp(self):
        self._config = Environment.get_config()
        self._host = self._config['vcd']['host']
        self._org = self._config['vcd']['sys_org_name']
        self._user = self._config['vcd']['sys_admin_username']
        self._pass = self._config['vcd']['sys_admin_pass']

        self._logger = Environment.get_default_logger()
예제 #51
0
    def setUp(self):
        self._config = Environment.get_config()
        self._host = self._config['vcd']['host']
        self._org = self._config['vcd']['sys_org_name']
        self._user = self._config['vcd']['sys_admin_username']
        self._pass = self._config['vcd']['sys_admin_pass']

        self._logger = Environment.get_default_logger()
예제 #52
0
 def test_0055_exit_maintenance_mode(self):
     logger = Environment.get_default_logger()
     vapp_name = TestVApp._customized_vapp_name
     vapp = Environment.get_vapp_in_test_vdc(
         client=TestVApp._sys_admin_client, vapp_name=vapp_name)
     logger.debug('Exiting maintenance mode of vApp ' + vapp_name)
     vapp.reload()
     result = vapp.exit_maintenance_mode()
     self.assertEqual(result, None)
예제 #53
0
 def test_0053_discard_suspended_state_vapp(self):
     logger = Environment.get_default_logger()
     vapp_name = TestVApp._customized_vapp_name
     vapp = Environment.get_vapp_in_test_vdc(
         client=TestVApp._sys_admin_client, vapp_name=vapp_name)
     logger.debug('Discarding suspended state of vApp ' + vapp_name)
     vapp.reload()
     task = vapp.discard_suspended_state_vapp()
     result = TestVApp._client.get_task_monitor().wait_for_success(task)
     self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
예제 #54
0
    def setUp(self):
        """Load configuration and create a click runner to invoke CLI."""
        self._config = Environment.get_config()
        self._host = self._config['vcd']['host']
        self._org = self._config['vcd']['sys_org_name']
        self._admin_user = self._config['vcd']['sys_admin_username']
        self._admin_pass = self._config['vcd']['sys_admin_pass']
        self._logger = Environment.get_default_logger()

        self._runner = CliRunner()
예제 #55
0
파일: vm_tests.py 프로젝트: vmware/pyvcloud
    def test_0061_install_vmware_tools(self):
        """Test the method related to install vmware tools in vm.py.
        This test passes if install vmware tools operation is successful.
        """
        logger = Environment.get_default_logger()
        vm_name = TestVM._test_vapp_first_vm_name
        vm = VM(TestVM._client, href=TestVM._test_vapp_first_vm_href)

        logger.debug('Installing Vmware Tools in VM:  ' + vm_name)
        task = vm.install_vmware_tools()
        result = TestVM._client.get_task_monitor().wait_for_success(task=task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
예제 #56
0
파일: vm_tests.py 프로젝트: vmware/pyvcloud
 def test_0063_eject_cd(self):
     """Test the method related to eject CD in vm.py.
     This test passes if eject CD operation is successful.
     """
     logger = Environment.get_default_logger()
     vm_name = TestVM._test_vapp_first_vm_name
     vm = VM(TestVM._client, href=TestVM._test_vapp_first_vm_href)
     media_href = TestVM._media_resource.Entity.get('href')
     logger.debug('Ejecting CD from VM:  ' + vm_name)
     task = vm.eject_cd(media_href)
     result = TestVM._client.get_task_monitor().wait_for_success(task=task)
     self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
예제 #57
0
파일: vcd_user.py 프로젝트: vmware/pyvcloud
    def test_0040_update_user_role(self):
        """Test the method Client.update_user().

        This test passes if the method is able to update an existing user role
        with a supplied user role.
        """
        logger = Environment.get_default_logger()
        logger.debug('Update org_user role from vApp User tp vApp Author')
        updated_user = TestUser._org.update_user(
            TestUser._org_user, role_name=TestUser._vapp_author_role)
        updated_user_role = updated_user['Role'].get('name')

        self.assertEqual(updated_user_role, TestUser._vapp_author_role)
예제 #58
0
    def test_0100_vapp_metadata(self):
        """Test the methods related to metadata manipulation in vapp.py.

        This test passes if all the metadata operations are successful.
        """
        logger = Environment.get_default_logger()
        vapp_name = TestVApp._empty_vapp_name
        vapp = Environment.get_vapp_in_test_vdc(
            client=TestVApp._client, vapp_name=vapp_name)

        # add new metadata
        logger.debug(f'Adding metadata [key={TestVApp._metadata_key},'
                     'value={TestVApp._metadata_value}]) to vApp:'
                     '{vapp_name}')
        task = vapp.set_metadata(
            domain=MetadataDomain.GENERAL.value,
            visibility=MetadataVisibility.READ_WRITE,
            key=TestVApp._metadata_key,
            value=TestVApp._metadata_value)
        result = TestVApp._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)

        # retrieve metadata
        logger.debug(f'Retriving metadata with key='
                     '{TestVApp._metadata_key} from vApp:{vapp_name}.')
        entries = metadata_to_dict(vapp.get_metadata())
        self.assertTrue(
            TestVApp._metadata_key in entries, f'Should have '
            'been able to retrieve metadata entry with '
            'key={TestVApp._metadata_key}.')

        # update metadata value as org admin
        logger.debug(f'Updtaing metadata on vApp:{vapp_name} with key='
                     '{TestVApp._metadata_key} to value='
                     '{TestVApp._metadata_new_value}.')
        task = vapp.set_metadata(
            domain=MetadataDomain.GENERAL.value,
            visibility=MetadataVisibility.READ_WRITE,
            key=TestVApp._metadata_key,
            value=TestVApp._metadata_new_value)
        TestVApp._client.get_task_monitor().wait_for_success(task)
        entries = metadata_to_dict(vapp.get_metadata())
        self.assertEqual(TestVApp._metadata_new_value,
                         entries[TestVApp._metadata_key])

        # remove metadata entry
        logger.debug(f'Removing metadata with '
                     'key={TestVApp._metadata_key} from vApp:{vapp_name}.')
        task = vapp.remove_metadata(key=TestVApp._metadata_key)
        result = TestVApp._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
예제 #59
0
파일: vm_tests.py 프로젝트: vmware/pyvcloud
    def test_0050_customize_vm(self):
        """Test the methods to update and retrieve memory and cpu of a vm.

        The test passes if the update operations are successful and the values
        retrieved thereafter matches the expected values.
        """
        logger = Environment.get_default_logger()
        vm_name = TestVM._test_vapp_first_vm_name
        vm = VM(TestVM._client, href=TestVM._test_vapp_first_vm_href)

        old_num_cpu_data = vm.get_cpus()
        self.assertEqual(old_num_cpu_data['num_cpus'],
                         TestVM._test_vapp_first_vm_num_cpu)

        old_memory_size = vm.get_memory()
        self.assertEqual(old_memory_size,
                         TestVM._test_vapp_first_vm_memory_size)

        # vm can be updated only when it's powered off
        if not vm.is_powered_off():
            task = vm.power_off()
            TestVM._client.get_task_monitor().wait_for_success(task)
            vm.reload()

        logger.debug('Updating number of cpus of vm ' + vm_name + ' to ' +
                     str(TestVM._test_vapp_first_vm_new_num_cpu))
        task = vm.modify_cpu(
            virtual_quantity=TestVM._test_vapp_first_vm_new_num_cpu)
        result = TestVM._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
        vm.reload()

        new_num_cpu_data = vm.get_cpus()
        self.assertEqual(new_num_cpu_data['num_cpus'],
                         TestVM._test_vapp_first_vm_new_num_cpu)

        logger.debug('Updating memory size of vm ' + vm_name + ' to ' +
                     str(TestVM._test_vapp_first_vm_new_memory_size))
        task = vm.modify_memory(TestVM._test_vapp_first_vm_new_memory_size)
        result = TestVM._client.get_task_monitor().wait_for_success(task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
        vm.reload()

        new_memory_size = vm.get_memory()
        self.assertEqual(new_memory_size,
                         TestVM._test_vapp_first_vm_new_memory_size)

        # power the vm back on
        task = vm.power_on()
        TestVM._client.get_task_monitor().wait_for_success(task)
예제 #60
0
    def test_9998_teardown(self):
        """Test the method Platform.delete_external_network().

        Invoke the method for the external network created by setup.

        This test passes if the task for deleting the external network
        succeeds.
        """
        logger = Environment.get_default_logger()
        platform = Platform(TestExtNet._sys_admin_client)
        task = platform.delete_external_network(TestExtNet._name)
        TestExtNet._sys_admin_client.get_task_monitor().wait_for_success(
            task=task)
        logger.debug('Deleted external network ' + TestExtNet._name + '.')