Esempio n. 1
0
def vcn_and_subnets(network_client):
    from tests import util

    with test_config_container.create_vcr().use_cassette(
            '_conftest_fixture_vcn_and_subnets.yml'):
        # create VCN
        vcn_name = util.random_name('cli_lb_test_vcn')
        cidr_block = "10.0.0.0/16"
        vcn_dns_label = util.random_name('vcn', insert_underscore=False)

        create_vcn_details = oci.core.models.CreateVcnDetails()
        create_vcn_details.cidr_block = cidr_block
        create_vcn_details.display_name = vcn_name
        create_vcn_details.compartment_id = os.environ[
            'OCI_CLI_COMPARTMENT_ID']
        create_vcn_details.dns_label = vcn_dns_label

        result = network_client.create_vcn(create_vcn_details)
        vcn_ocid = result.data.id
        assert result.status == 200

        oci.wait_until(network_client,
                       network_client.get_vcn(vcn_ocid),
                       'lifecycle_state',
                       'AVAILABLE',
                       max_wait_seconds=300,
                       max_interval_seconds=WAIT_INTERVAL_SECONDS)

        # create subnet in first AD
        subnet_name = util.random_name('cli_lb_test_subnet')
        cidr_block = "10.0.1.0/24"
        subnet_dns_label = util.random_name('subnet', insert_underscore=False)

        create_subnet_details = oci.core.models.CreateSubnetDetails()
        create_subnet_details.compartment_id = os.environ[
            'OCI_CLI_COMPARTMENT_ID']
        create_subnet_details.availability_domain = util.availability_domain()
        create_subnet_details.display_name = subnet_name
        create_subnet_details.vcn_id = vcn_ocid
        create_subnet_details.cidr_block = cidr_block
        create_subnet_details.dns_label = subnet_dns_label

        result = network_client.create_subnet(create_subnet_details)
        subnet_ocid_1 = result.data.id
        assert result.status == 200

        oci.wait_until(network_client,
                       network_client.get_subnet(subnet_ocid_1),
                       'lifecycle_state',
                       'AVAILABLE',
                       max_wait_seconds=300,
                       max_interval_seconds=WAIT_INTERVAL_SECONDS)

        # create subnet in second AD
        subnet_name = util.random_name('cli_lb_test_subnet')
        cidr_block = "10.0.0.0/24"
        subnet_dns_label = util.random_name('subnet2', insert_underscore=False)

        create_subnet_details = oci.core.models.CreateSubnetDetails()
        create_subnet_details.compartment_id = os.environ[
            'OCI_CLI_COMPARTMENT_ID']
        create_subnet_details.availability_domain = util.second_availability_domain(
        )
        create_subnet_details.display_name = subnet_name
        create_subnet_details.vcn_id = vcn_ocid
        create_subnet_details.cidr_block = cidr_block
        create_subnet_details.dns_label = subnet_dns_label

        result = network_client.create_subnet(create_subnet_details)
        subnet_ocid_2 = result.data.id
        assert result.status == 200

        oci.wait_until(network_client,
                       network_client.get_subnet(subnet_ocid_2),
                       'lifecycle_state',
                       'AVAILABLE',
                       max_wait_seconds=300,
                       max_interval_seconds=WAIT_INTERVAL_SECONDS)

    yield [vcn_ocid, subnet_ocid_1, subnet_ocid_2]

    # For some reason VCR doesn't like that the post-yield stuff here is all in one cassette. Splitting into different cassettes seems to work
    with test_config_container.create_vcr().use_cassette(
            '_conftest_fixture_vcn_and_subnets_delete.yml'):
        # delete VCN and subnets
        network_client.delete_subnet(subnet_ocid_1)

        try:
            oci.wait_until(network_client,
                           network_client.get_subnet(subnet_ocid_1),
                           'lifecycle_state',
                           'TERMINATED',
                           max_wait_seconds=600,
                           max_interval_seconds=WAIT_INTERVAL_SECONDS)
        except oci.exceptions.ServiceError as error:
            if not hasattr(error, 'status') or error.status != 404:
                util.print_latest_exception(error)

        network_client.delete_subnet(subnet_ocid_2)

        try:
            oci.wait_until(network_client,
                           network_client.get_subnet(subnet_ocid_2),
                           'lifecycle_state',
                           'TERMINATED',
                           max_wait_seconds=600,
                           max_interval_seconds=WAIT_INTERVAL_SECONDS)
        except oci.exceptions.ServiceError as error:
            if not hasattr(error, 'status') or error.status != 404:
                util.print_latest_exception(error)

        network_client.delete_vcn(vcn_ocid)
Esempio n. 2
0
    def subtest_volume_backup_operations(self):
        backup_name = util.random_name('cli_test_backup')
        result = self.invoke([
            'backup', 'create', '--volume-id', self.volume_id,
            '--display-name', backup_name
        ])
        util.validate_response(result)
        self.backup_id = util.find_id_in_response(result.output)

        util.wait_until(
            ['bv', 'backup', 'get', '--volume-backup-id', self.backup_id],
            'AVAILABLE',
            max_wait_seconds=600)

        result = self.invoke(
            ['backup', 'get', '--volume-backup-id', self.backup_id])
        util.validate_response(result)
        parsed_result = json.loads(result.output)
        assert parsed_result['data']['size-in-gbs'] is not None
        assert parsed_result['data']['size-in-mbs'] is not None
        assert parsed_result['data']['unique-size-in-gbs'] is not None
        assert parsed_result['data']['unique-size-in-mbs'] is not None

        result = self.invoke(
            ['backup', 'list', '--compartment-id', util.COMPARTMENT_ID])
        util.validate_response(result)

        result = self.invoke([
            'backup', 'list', '--compartment-id', util.COMPARTMENT_ID,
            '--volume-id', self.volume_id
        ])
        util.validate_response(result)
        self.assertEquals(1, len(json.loads(result.output)['data']))

        retrieve_list_and_ensure_sorted([
            'bv', 'backup', 'list', '-c', util.COMPARTMENT_ID, '--sort-by',
            'DISPLAYNAME', '--sort-order', 'asc'
        ], 'display-name', 'asc')
        retrieve_list_and_ensure_sorted([
            'bv', 'backup', 'list', '-c', util.COMPARTMENT_ID, '--sort-by',
            'DISPLAYNAME', '--sort-order', 'desc'
        ], 'display-name', 'desc')
        retrieve_list_and_ensure_sorted([
            'bv', 'backup', 'list', '-c', util.COMPARTMENT_ID, '--sort-by',
            'TIMECREATED', '--sort-order', 'asc', '--all'
        ], 'time-created', 'asc')
        retrieve_list_and_ensure_sorted([
            'bv', 'backup', 'list', '-c', util.COMPARTMENT_ID, '--sort-by',
            'TIMECREATED', '--sort-order', 'desc', '--all'
        ], 'time-created', 'desc')

        backup_name = backup_name + "_UPDATED"
        result = self.invoke([
            'backup', 'update', '--volume-backup-id', self.backup_id,
            '--display-name', backup_name
        ])
        util.validate_response(result)

        result = self.invoke([
            'volume', 'create', '--volume-backup-id', self.backup_id,
            '--availability-domain',
            util.second_availability_domain()
        ])
        util.validate_response(result)

        parsed_result = json.loads(result.output)
        source_details = {'id': self.backup_id, 'type': 'volumeBackup'}
        assert source_details == parsed_result['data']['source-details']
        assert util.second_availability_domain(
        ) == parsed_result['data']['availability-domain']
        assert 50 == int(parsed_result['data']
                         ['size-in-gbs'])  # We initially created a 50GB volume

        volume_id = util.find_id_in_response(result.output)
        util.wait_until(['bv', 'volume', 'get', '--volume-id', volume_id],
                        'AVAILABLE',
                        max_wait_seconds=600)

        result = self.invoke(
            ['volume', 'delete', '--volume-id', volume_id, '--force'])
        util.validate_response(result)

        # Make sure we're still in a good state before deleting.
        util.wait_until(
            ['bv', 'backup', 'get', '--volume-backup-id', self.backup_id],
            'AVAILABLE',
            max_interval_seconds=180)