def mount_target(filestorage_client, vcn_and_subnet, runner, config_file, config_profile): with test_config_container.create_vcr( cassette_library_dir=CASSETTE_LIBRARY_DIR).use_cassette( 'filestorage_mount_target_fixture.yml'): vcn_id = vcn_and_subnet[0] subnet_id = vcn_and_subnet[1] mount_target_name = util.random_name('cli_test_mt') params = [ 'mount-target', 'create', '--availability-domain', util.availability_domain(), '-c', util.COMPARTMENT_ID, '--subnet-id', subnet_id ] result = invoke(runner, config_file, config_profile, params) util.validate_response(result) mount_target = json.loads(result.output)['data'] mount_target_id = mount_target['id'] test_config_container.do_wait( filestorage_client, filestorage_client.get_mount_target(mount_target_id), 'lifecycle_state', 'ACTIVE') # exercise CLI get mount target params = ['mount-target', 'get', '--mount-target-id', mount_target_id] result = invoke(runner, config_file, config_profile, params) util.validate_response(result) yield mount_target with test_config_container.create_vcr( cassette_library_dir=CASSETTE_LIBRARY_DIR).use_cassette( 'filestorage_mount_target_fixture_cleanup.yml'): params = [ 'mount-target', 'delete', '--mount-target-id', mount_target_id, '--force' ] result = invoke(runner, config_file, config_profile, params) util.validate_response(result) util.wait_until([ 'fs', 'mount-target', 'get', '--mount-target-id', mount_target_id ], 'DELETED', max_wait_seconds=300)
def vcn_and_subnet(runner, config_file, config_profile, network_client): with test_config_container.create_vcr( cassette_library_dir=CASSETTE_LIBRARY_DIR).use_cassette( 'apigateway_vcn_and_subnet_fixture.yml'): # create VCN vcn_name = util.random_name('cli_db_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 = util.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) # create subnet in first AD subnet_name = util.random_name('python_cli_test_subnet') cidr_block = "10.0.1.0/24" subnet_dns_label = util.random_name('subnet', insert_underscore=False) + '1' create_subnet_details = oci.core.models.CreateSubnetDetails() create_subnet_details.compartment_id = util.COMPARTMENT_ID 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 = result.data.id assert result.status == 200 oci.wait_until(network_client, network_client.get_subnet(subnet_ocid), 'lifecycle_state', 'AVAILABLE', max_wait_seconds=300) yield vcn_ocid, subnet_ocid # # this code does not run inside the vcr_fixture because it is outside any test function # # thus we are explicitly creating a separate cassette for it here with test_config_container.create_vcr( cassette_library_dir=CASSETTE_LIBRARY_DIR).use_cassette( 'apigateway_vcn_and_subnet_fixture_cleanup.yml'): # Sometimes we can't delete the subnet straight after the mount target because some VNIC is still # hanging around. If we get a conflict, try a few times before bailing out attempts = 0 while attempts < 5: try: network_client.delete_subnet(subnet_ocid) test_config_container.do_wait( network_client, network_client.get_subnet(subnet_ocid), 'lifecycle_state', 'TERMINATED', max_wait_seconds=600, succeed_on_not_found=True) break except oci.exceptions.ServiceError as e: attempts += 1 if e.status == 409 and attempts < 5: time.sleep(5) # succeed_on_not_found doesn't work as expected elif e.status == 404: break else: raise network_client.delete_vcn(vcn_ocid)