Example #1
0
    def test_all_operations(self):
        """Successfully calls every operation with basic options. The exceptions are 'vnic get' and 'vnic update', which are tested
        in test_compute.py since they require an instance.

        We also have exceptions for private-ip get/update/delete/list and attaching and detaching private IPs from VNICs, as
        these are handlde in test_secondary_private_ip.py"""
        with test_config_container.create_vcr(
                cassette_library_dir=CASSETTE_LIBRARY_DIR).use_cassette(
                    'virtual_network.yml'):
            try:
                self.subtest_vcn_operations()
                self.subtest_security_list_operations()
                self.subtest_security_list_stateless_rules()
                self.subtest_subnet_operations()
                self.subtest_internet_gateway_operations()
                self.subtest_cpe_operations()
                self.subtest_dhcp_option_operations()
                self.subtest_drg_operations()
                self.subtest_drg_attachment_operations()
                self.subtest_ip_sec_connection_operations()
                self.subtest_route_table_operations()

                if hasattr(self, 'drg_capacity_issue'):
                    pytest.skip('Skipped DRG tests due to capacity issues')
            finally:
                util.vcr_mode_aware_sleep(20)
                self.subtest_delete()
Example #2
0
    def subtest_instance_console_connections_tagging(self):
        tag_names_to_values = {}
        for t in tag_data_container.tags:
            tag_names_to_values[t.name] = 'somevalue {}'.format(t.name)
        tag_data_container.write_defined_tags_to_file(
            os.path.join('tests', 'temp', 'defined_tags_compute.json'),
            tag_data_container.tag_namespace,
            tag_names_to_values
        )

        result = self.invoke([
            'compute', 'instance-console-connection', 'create',
            '--instance-id', self.instance_ocid,
            '--ssh-public-key-file', util.SSH_AUTHORIZED_KEYS_FILE,
            '--freeform-tags', 'file://tests/resources/tagging/freeform_tags_1.json',
            '--defined-tags', 'file://tests/temp/defined_tags_compute.json'
        ])
        util.validate_response(result)
        instance_console_connection_details = json.loads(result.output)
        expected_freeform = {'tagOne': 'value1', 'tag_Two': 'value two'}
        expected_defined = {tag_data_container.tag_namespace.name: tag_names_to_values}
        self.assertEquals(expected_freeform, instance_console_connection_details['data']['freeform-tags'])
        self.assertEquals(expected_defined, instance_console_connection_details['data']['defined-tags'])

        self.invoke(['compute', 'instance-console-connection', 'delete', '--instance-console-connection-id', instance_console_connection_details['data']['id'], '--force'])
        result = self.invoke(['compute', 'instance-console-connection', 'get', '--instance-console-connection-id', instance_console_connection_details['data']['id']])
        parsed_result = json.loads(result.output)
        if 'DELET' not in parsed_result['data']['lifecycle-state']:
            print("parsed_result=" + str(parsed_result) + ", lifecycle-state=" + str(parsed_result['data']['lifecycle-state']))
            util.vcr_mode_aware_sleep(60)
            result = self.invoke(['compute', 'instance-console-connection', 'get', '--instance-console-connection-id', instance_console_connection_details['data']['id']])
            parsed_result = json.loads(result.output)
        self.assertTrue(parsed_result['data']['lifecycle-state'] == 'DELETED' or parsed_result['data']['lifecycle-state'] == 'DELETING')
Example #3
0
 def subtest_instance_action_operations(self):
     result = self.invoke(['compute', 'instance', 'action', '--instance-id', self.instance_ocid, '--action', 'RESET'])
     util.validate_response(result)
     util.vcr_mode_aware_sleep(10)
     util.wait_until(['compute', 'instance', 'get', '--instance-id', self.instance_ocid], 'RUNNING',
                     max_wait_seconds=300)
     util.vcr_mode_aware_sleep(5)
Example #4
0
    def subtest_dhcp_option_operations(self):
        dhcp_options_name = util.random_name('cli_test_dhcp_options')
        options = util.remove_outer_quotes(oci_cli_virtual_network.virtualnetwork_cli_extended.network_create_dhcp_options_options_example)

        result = self.invoke(
            ['dhcp-options', 'create',
             '--compartment-id', util.COMPARTMENT_ID,
             '--vcn-id', self.vcn_ocid,
             '--display-name', dhcp_options_name,
             '--options', options
             ])
        util.validate_response(result, expect_etag=True)
        self.dhcp_options_ocid = util.find_id_in_response(result.output)
        util.wait_until(['network', 'dhcp-options', 'get', '--dhcp-id', self.dhcp_options_ocid], 'AVAILABLE')

        result = self.invoke(['dhcp-options', 'list', '--compartment-id', util.COMPARTMENT_ID, '--vcn-id', self.vcn_ocid])
        util.validate_response(result)

        self.run_list_filter_verification('dhcp-options', dhcp_options_name)

        result = self.invoke(['dhcp-options', 'get', '--dhcp-id', self.dhcp_options_ocid])
        util.validate_response(result, expect_etag=True)

        dhcp_options_name = dhcp_options_name + "_updated"
        options_v2 = """[{"type": "DomainNameServer", "customDnsServers": ["202.44.61.10"], "serverType": "CustomDnsServer"},
            {"searchDomainNames": ["testvcn.oraclevcn.com"], "type":"SearchDomain"}]"""

        # update display name only - does not show a confirmation prompt
        result = self.invoke(['dhcp-options', 'update', '--dhcp-id', self.dhcp_options_ocid, '--display-name', dhcp_options_name])
        util.validate_response(result, expect_etag=True)

        # update options, confirm y
        result = self.invoke(
            ['dhcp-options', 'update', '--dhcp-id', self.dhcp_options_ocid, '--options', options_v2], input='y')
        util.validate_response(result, json_response_expected=False)

        # update options, confirm n
        result = self.invoke(
            ['dhcp-options', 'update', '--dhcp-id', self.dhcp_options_ocid, '--options', options], input='n')
        assert result.exit_code != 0

        util.vcr_mode_aware_sleep(20)

        # update options, force
        result = self.invoke(
            ['dhcp-options', 'update', '--dhcp-id', self.dhcp_options_ocid, '--options', options_v2, '--force'])

        util.validate_response(result, expect_etag=True)

        response = json.loads(result.output)

        # validate response contains SearchDomain option
        response_has_search_domain_option = False
        for option in response["data"]["options"]:
            if option["type"] == "SearchDomain":
                response_has_search_domain_option = True
                assert option["search-domain-names"][0] == "testvcn.oraclevcn.com"

        assert response_has_search_domain_option, "Options response should contain option of type 'SearchDomain'."
Example #5
0
    def subtest_route_table_operations(self):
        rt_name = util.random_name('cli_test_route_table')
        rules = util.remove_outer_quotes(oci_cli_virtual_network.virtualnetwork_cli_extended.network_create_route_table_route_rules_example.format(ig_id=self.ig_ocid))

        result = self.invoke(
            ['route-table', 'create',
             '--compartment-id', util.COMPARTMENT_ID,
             '--display-name', rt_name,
             '--vcn-id', self.vcn_ocid,
             '--route-rules', rules
             ])
        self.rt_ocid = util.find_id_in_response(result.output)
        util.validate_response(result, expect_etag=True)

        util.wait_until(['network', 'route-table', 'get', '--rt-id', self.rt_ocid], 'AVAILABLE',
                        max_wait_seconds=300)

        result = self.invoke(['route-table', 'list', '--compartment-id', util.COMPARTMENT_ID, '--vcn-id', self.vcn_ocid])
        util.validate_response(result)

        self.run_list_filter_verification('route-table', rt_name)

        result = self.invoke(['route-table', 'get', '--rt-id', self.rt_ocid])
        util.validate_response(result, expect_etag=True)

        rt_name = rt_name + "_updated"
        rules_v2 = """[{{"cidrBlock":"0.0.0.0/1","networkEntityId":"{ig_id}"}}]""".format(ig_id=self.ig_ocid)

        # update display name only - does not show a prompt
        result = self.invoke(['route-table', 'update', '--rt-id', self.rt_ocid, '--display-name', rt_name])
        util.validate_response(result, expect_etag=True)

        util.vcr_mode_aware_sleep(20)

        # update route-rules, confirm y
        result = self.invoke(
            ['route-table', 'update', '--rt-id', self.rt_ocid, '--route-rules', rules_v2], input='y')
        util.validate_response(result, json_response_expected=False)

        # update route-rules, confirm n
        result = self.invoke(
            ['route-table', 'update', '--rt-id', self.rt_ocid, '--route-rules', rules_v2], input='n')
        assert result.exit_code != 0

        util.vcr_mode_aware_sleep(20)

        # update route-rules, force
        result = self.invoke(
            ['route-table', 'update', '--rt-id', self.rt_ocid, '--route-rules', rules, '--force'])
        util.validate_response(result, expect_etag=True)
Example #6
0
    def subtest_security_list_stateless_rules(self):

        util.vcr_mode_aware_sleep(10)

        stateless_egress_rule = """[{"destination": "10.0.2.0/24", "protocol": "6", "tcpOptions": {"destinationPortRange": {"max": 2, "min": 1}}, "isStateless":"true"}]"""
        result = self.invoke(
            ['security-list', 'update', '--security-list-id', self.sl_ocid, '--egress-security-rules', stateless_egress_rule,
             '--force'])
        util.validate_response(result, expect_etag=True)
        assert json.loads(result.output)["data"]["egress-security-rules"][0]["is-stateless"] is True

        util.vcr_mode_aware_sleep(20)

        explicit_stateful_egress_rule = """[{"destination": "10.0.2.0/24", "protocol": "6", "tcpOptions": {"destinationPortRange": {"max": 2, "min": 1}}, "isStateless":"false"}]"""
        result = self.invoke(
            ['security-list', 'update', '--security-list-id', self.sl_ocid, '--egress-security-rules',
             explicit_stateful_egress_rule,
             '--force'])
        util.validate_response(result, expect_etag=True)
        assert json.loads(result.output)["data"]["egress-security-rules"][0]["is-stateless"] is False

        util.vcr_mode_aware_sleep(20)

        implicit_stateful_egress_rule = """[{"destination": "10.0.2.0/24", "protocol": "17", "udpOptions": {"destinationPortRange": {"max": 2, "min": 1}, "sourcePortRange": {"max": 4, "min": 3}}}]"""
        result = self.invoke(
            ['security-list', 'update', '--security-list-id', self.sl_ocid, '--egress-security-rules',
             implicit_stateful_egress_rule,
             '--force'])
        util.validate_response(result, expect_etag=True)
        assert json.loads(result.output)["data"]["egress-security-rules"][0]["is-stateless"] is None
Example #7
0
    def subtest_instance_console_connections(self):
        result = self.invoke([
            'compute', 'instance-console-connection', 'create',
            '--instance-id', self.instance_ocid, '--ssh-public-key-file',
            util.SSH_AUTHORIZED_KEYS_FILE
        ])
        util.validate_response(result)

        instance_console_connection_details = json.loads(result.output)
        self.assertIsNotNone(
            instance_console_connection_details['data']['connection-string'])
        self.assertIsNotNone(instance_console_connection_details['data']['id'])
        self.assertIsNotNone(
            instance_console_connection_details['data']['lifecycle-state'])
        self.assertEquals(
            self.instance_ocid,
            instance_console_connection_details['data']['instance-id'])
        self.assertIsNotNone(
            instance_console_connection_details['data']['fingerprint'])

        result = self.invoke([
            'compute', 'instance-console-connection', 'get',
            '--instance-console-connection-id',
            instance_console_connection_details['data']['id']
        ])
        parsed_result = json.loads(result.output)
        self.assertEquals(instance_console_connection_details['data']['id'],
                          parsed_result['data']['id'])
        self.assertEquals(
            instance_console_connection_details['data']['instance-id'],
            parsed_result['data']['instance-id'])
        self.assertEquals(
            instance_console_connection_details['data']['fingerprint'],
            parsed_result['data']['fingerprint'])
        self.assertEquals(
            instance_console_connection_details['data']['compartment-id'],
            parsed_result['data']['compartment-id'])
        self.assertEquals(
            instance_console_connection_details['data']['connection-string'],
            parsed_result['data']['connection-string'])
        self.assertEquals(
            {}, instance_console_connection_details['data']['freeform-tags'])
        self.assertEquals(
            {}, instance_console_connection_details['data']['defined-tags'])
        self.assertIsNotNone(parsed_result['data']['lifecycle-state'])

        private_key_file = 'C:\\Users\\oci\console.ppk'  # noqa: W605
        params = [
            'compute', 'instance-console-connection',
            'get-plink-connection-string', '--instance-console-connection-id',
            instance_console_connection_details['data']['id'],
            '--private-key-file', private_key_file
        ]

        result = self.invoke(params)

        util.validate_response(result, json_response_expected=False)

        m = re.search(
            oci_cli_compute.compute_cli_extended.
            INSTANCE_CONSOLE_CONNECTION_STRING_INTERMEDIATE_HOST_REGEX,
            instance_console_connection_details['data']['connection-string'])
        intermediate_host = m.group(0)

        connection_template = 'Start-Job {{echo N | plink -ssh -N -i "{3}" -P 443 -l {1} {2} -L 5905:{0}:5905}}; sleep 5 ; plink -L 5900:localhost:5900 localhost -P 5905 -N -i "{3}" -l {1}'
        expected_plink_connection_string = connection_template.format(
            instance_console_connection_details['data']['instance-id'],
            instance_console_connection_details['data']['id'],
            intermediate_host, private_key_file)
        assert expected_plink_connection_string == result.output.strip()

        # confirm that error from internal call to GetConsoleConnection returns service error and non-zero status code
        params = [
            'compute', 'instance-console-connection',
            'get-plink-connection-string', '--instance-console-connection-id',
            'fake-instance-console-connection-id', '--private-key-file',
            private_key_file
        ]

        result = self.invoke(params)
        util.validate_service_error(result, error_message='ServiceError')

        keep_paginating = True
        next_page = None
        all_connections = []
        while keep_paginating:
            if next_page:
                result = self.invoke([
                    'compute', 'instance-console-connection', 'list',
                    '--compartment-id', util.COMPARTMENT_ID, '--page',
                    next_page
                ])
            else:
                result = self.invoke([
                    'compute', 'instance-console-connection', 'list',
                    '--compartment-id', util.COMPARTMENT_ID
                ])

            if result.output:
                parsed_result = json.loads(result.output)
                all_connections.extend(parsed_result['data'])
                if 'opc-next-page' in parsed_result:
                    next_page = parsed_result['opc-next-page']
                    keep_paginating = next_page is not None
                else:
                    keep_paginating = False
            else:
                keep_paginating = False

        match_found = False
        for conn in all_connections:
            if conn['id'] == instance_console_connection_details['data']['id']:
                match_found = True
                self.assertEquals(
                    instance_console_connection_details['data']['instance-id'],
                    conn['instance-id'])
                self.assertEquals(
                    instance_console_connection_details['data']['fingerprint'],
                    conn['fingerprint'])
                self.assertEquals(
                    instance_console_connection_details['data']
                    ['compartment-id'], conn['compartment-id'])
                self.assertEquals(
                    instance_console_connection_details['data']
                    ['connection-string'], conn['connection-string'])
                self.assertIsNotNone(conn['lifecycle-state'])
                break

        self.assertTrue(match_found)

        self.invoke([
            'compute', 'instance-console-connection', 'delete',
            '--instance-console-connection-id',
            instance_console_connection_details['data']['id'], '--force'
        ])

        result = self.invoke([
            'compute', 'instance-console-connection', 'get',
            '--instance-console-connection-id',
            instance_console_connection_details['data']['id']
        ])
        parsed_result = json.loads(result.output)
        if 'DELET' not in parsed_result['data']['lifecycle-state']:
            print("parsed_result=" + str(parsed_result) +
                  ", lifecycle-state=" +
                  str(parsed_result['data']['lifecycle-state']))
            util.vcr_mode_aware_sleep(60)
            result = self.invoke([
                'compute', 'instance-console-connection', 'get',
                '--instance-console-connection-id',
                instance_console_connection_details['data']['id']
            ])
            parsed_result = json.loads(result.output)
        self.assertTrue(
            parsed_result['data']['lifecycle-state'] == 'DELETED'
            or parsed_result['data']['lifecycle-state'] == 'DELETING')
Example #8
0
    def subtest_public_ip_operations(self):
        # Attach a new vnic
        vnic_display_name = 'myfloatingipvnic'
        vnic_private_ip = '10.0.0.200'
        result = self.invoke([
            'compute', 'instance', 'attach-vnic', '--instance-id',
            self.instance_ocid, '--subnet-id', self.subnet_ocid,
            '--vnic-display-name', vnic_display_name, '--assign-public-ip',
            'true', '--private-ip', vnic_private_ip, '--wait'
        ])
        util.validate_response(result)
        second_vnic = json.loads(result.output)['data']
        second_vnic_id = second_vnic['id']

        # Extract the properties of the new secondary vnic.
        result = self.invoke(
            ['network', 'vnic', 'get', '--vnic-id', second_vnic_id])
        util.validate_response(result)
        second_vnic = json.loads(result.output)['data']
        vnic_resp_private_ip = second_vnic['private-ip']
        vnic_resp_public_ip = second_vnic['public-ip']
        self.assertEquals(vnic_private_ip, vnic_resp_private_ip)
        self.assertNotEquals(None, vnic_resp_public_ip)

        # Some extra time is needed after VNIC operations for state to stabilize.
        util.vcr_mode_aware_sleep(5)

        # Verify the public IP operations. Verify that each get below returns the same values for
        # public-ip-address, public-ip-id and private-ip-id since it is for the same public IP object
        # 1. get --public-ip-address
        result = self.invoke([
            'network', 'public-ip', 'get', '--public-ip-address',
            vnic_resp_public_ip
        ])
        util.validate_response(result)
        public_ip_obj = json.loads(result.output)['data']
        resp_public_ip_id = public_ip_obj['id']
        resp_private_ip_id = public_ip_obj['private-ip-id']
        resp_public_ip_addr = public_ip_obj['ip-address']
        self.assertEquals(vnic_resp_public_ip, resp_public_ip_addr)

        # 2. get --public-ip-id
        result = self.invoke([
            'network', 'public-ip', 'get', '--public-ip-id', resp_public_ip_id
        ])
        util.validate_response(result)
        public_ip_obj = json.loads(result.output)['data']
        resp_private_ip_id_2 = public_ip_obj['private-ip-id']
        resp_public_ip_addr_2 = public_ip_obj['ip-address']
        self.assertEquals(resp_private_ip_id, resp_private_ip_id_2)
        self.assertEquals(resp_public_ip_addr, resp_public_ip_addr_2)

        # 3. get --private-ip-id
        result = self.invoke([
            'network', 'public-ip', 'get', '--private-ip-id',
            resp_private_ip_id
        ])
        util.validate_response(result)
        public_ip_obj = json.loads(result.output)['data']
        resp_public_ip_id_3 = public_ip_obj['id']
        resp_public_ip_addr_3 = public_ip_obj['ip-address']
        self.assertEquals(resp_public_ip_id, resp_public_ip_id_3)
        self.assertEquals(resp_public_ip_addr, resp_public_ip_addr_3)

        # Get the secondary attachment ID
        result = self.invoke([
            'compute', 'vnic-attachment', 'list', '--compartment-id',
            util.COMPARTMENT_ID, '--vnic-id', second_vnic_id
        ])
        util.validate_response(result)
        json_data = json.loads(result.output)
        self.assertEquals(1, len(json_data['data']))
        second_vnic_attachment_id = json_data['data'][0]['id']

        # Detach vnic
        result = self.invoke([
            'compute', 'instance', 'detach-vnic', '--vnic-id', second_vnic_id,
            '--compartment-id', util.COMPARTMENT_ID, '--force'
        ])
        util.validate_response(result)
        util.wait_until([
            'compute', 'vnic-attachment', 'get', '--vnic-attachment-id',
            second_vnic_attachment_id
        ],
                        'DETACHED',
                        max_wait_seconds=300,
                        succeed_if_not_found=True)

        util.vcr_mode_aware_sleep(10)
Example #9
0
    def subtest_vnic_operations(self):
        result = self.invoke([
            'compute', 'vnic-attachment', 'list', '--compartment-id',
            util.COMPARTMENT_ID, '--instance-id', self.instance_ocid
        ])
        util.validate_response(result)
        json_data = json.loads(result.output)
        assert (len(json_data['data']) == 1)
        vnic_id = json_data['data'][0]['vnic-id']

        # Test get vnic, since this is not tested in test_virtualnetwork.py.
        result = self.invoke(['network', 'vnic', 'get', '--vnic-id', vnic_id])
        util.validate_response(result)

        # Attach a new vnic with --wait and all params set.
        vnic_display_name = 'mysecondvnic'
        vnic_hostname_label = 'myotherhostname'
        vnic_private_ip = '10.0.0.121'
        result = self.invoke([
            'compute', 'instance', 'attach-vnic', '--instance-id',
            self.instance_ocid, '--subnet-id', self.subnet_ocid,
            '--vnic-display-name', vnic_display_name, '--assign-public-ip',
            'false', '--private-ip', vnic_private_ip, '--hostname-label',
            vnic_hostname_label, '--nic-index', '0', '--wait'
        ])
        util.validate_response(result)
        second_vnic = json.loads(result.output)['data']
        second_vnic_id = second_vnic['id']

        # Ensure that all properties set in attach-vnic were set.
        result = self.invoke(
            ['network', 'vnic', 'get', '--vnic-id', second_vnic_id])
        util.validate_response(result)
        second_vnic = json.loads(result.output)['data']
        self.assertEquals(vnic_hostname_label, second_vnic['hostname-label'])
        self.assertEquals(vnic_private_ip, second_vnic['private-ip'])
        self.assertEquals(vnic_display_name, second_vnic['display-name'])
        self.assertEquals(None, second_vnic['public-ip'])

        # Some extra time is needed after VNIC CRUD operations for state to stabilize.
        util.vcr_mode_aware_sleep(5)

        # Ensure that new attachments are listed.
        result = self.invoke([
            'compute', 'vnic-attachment', 'list', '--compartment-id',
            util.COMPARTMENT_ID, '--instance-id', self.instance_ocid
        ])
        util.validate_response(result)
        json_data = json.loads(result.output)
        self.assertEquals(2, len(json_data['data']))

        # Update vnic
        result = self.invoke([
            'network', 'vnic', 'update', '--vnic-id', second_vnic_id,
            '--display-name', 'newdisplayname', '--hostname-label',
            'newhostnamelabel'
        ])
        util.validate_response(result)

        # Get the secondary attachment ID
        result = self.invoke([
            'compute', 'vnic-attachment', 'list', '--compartment-id',
            util.COMPARTMENT_ID, '--vnic-id', second_vnic_id
        ])
        util.validate_response(result)
        json_data = json.loads(result.output)
        self.assertEquals(1, len(json_data['data']))
        second_vnic_attachment_id = json_data['data'][0]['id']

        result = self.invoke([
            'compute', 'vnic-attachment', 'get', '--vnic-attachment-id',
            second_vnic_attachment_id
        ])
        util.validate_response(result)

        util.vcr_mode_aware_sleep(10)

        # Detach vnic
        result = self.invoke([
            'compute', 'instance', 'detach-vnic', '--vnic-id', second_vnic_id,
            '--compartment-id', util.COMPARTMENT_ID, '--force'
        ])
        util.validate_response(result)
        util.wait_until([
            'compute', 'vnic-attachment', 'get', '--vnic-attachment-id',
            second_vnic_attachment_id
        ],
                        'DETACHED',
                        max_wait_seconds=300,
                        succeed_if_not_found=True)

        util.vcr_mode_aware_sleep(10)
Example #10
0
    def subtest_security_list_operations(self):
        sl_name = util.random_name('cli_test_security_list')
        egress_rules = util.remove_outer_quotes(
            oci_cli_virtual_network.virtualnetwork_cli_extended.
            network_create_security_list_egress_security_rules_example)
        ingress_rules = util.remove_outer_quotes(
            oci_cli_virtual_network.virtualnetwork_cli_extended.
            network_create_security_list_ingress_security_rules_example)

        result = self.invoke([
            'security-list', 'create', '--compartment-id', util.COMPARTMENT_ID,
            '--display-name', sl_name, '--vcn-id', self.vcn_ocid,
            '--egress-security-rules', egress_rules,
            '--ingress-security-rules', ingress_rules
        ])
        self.sl_ocid = util.find_id_in_response(result.output)
        util.validate_response(result, expect_etag=True)

        util.wait_until([
            'network', 'security-list', 'get', '--security-list-id',
            self.sl_ocid
        ],
                        'AVAILABLE',
                        max_wait_seconds=300)

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

        self.run_list_filter_verification('security-list', sl_name)

        result = self.invoke(
            ['security-list', 'get', '--security-list-id', self.sl_ocid])
        util.validate_response(result, expect_etag=True)

        sl_name = sl_name + "_updated"
        egress_rules_v2 = """[{"destination": "10.0.2.0/24", "protocol": "6", "tcpOptions": {"destinationPortRange": {"max": 1522, "min": 1522}}}]"""
        ingress_rules_v2 = """[{"protocol": "6", "source": "10.0.1.0/25", "tcpOptions": {"destinationPortRange": {"max": 1521, "min": 1521}}}]"""

        # TODO: A short sleep before every security list update to allow for replication.
        util.vcr_mode_aware_sleep(20)

        # Force update on all fields
        result = self.invoke([
            'security-list', 'update', '--security-list-id', self.sl_ocid,
            '--display-name', sl_name, '--egress-security-rules', egress_rules,
            '--ingress-security-rules', ingress_rules, '--force'
        ])
        util.validate_response(result, expect_etag=True)

        util.vcr_mode_aware_sleep(20)

        # update display name only - does not show a prompt
        result = self.invoke([
            'security-list', 'update', '--security-list-id', self.sl_ocid,
            '--display-name', sl_name
        ])
        util.validate_response(result, expect_etag=True)

        util.vcr_mode_aware_sleep(20)

        # update egress-rules, confirm y
        result = self.invoke([
            'security-list', 'update', '--security-list-id', self.sl_ocid,
            '--egress-security-rules', egress_rules_v2
        ],
                             input='y')
        util.validate_response(result, json_response_expected=False)

        util.vcr_mode_aware_sleep(20)

        # update ingress-rules, confirm y
        result = self.invoke([
            'security-list', 'update', '--security-list-id', self.sl_ocid,
            '--ingress-security-rules', ingress_rules_v2
        ],
                             input='y')
        util.validate_response(result, json_response_expected=False)

        util.vcr_mode_aware_sleep(20)

        # update both, confirm y
        result = self.invoke([
            'security-list', 'update', '--security-list-id', self.sl_ocid,
            '--ingress-security-rules', ingress_rules,
            '--egress-security-rules', egress_rules
        ],
                             input='y')
        util.validate_response(result, json_response_expected=False)

        util.vcr_mode_aware_sleep(20)

        # update egress-rules, confirm n
        result = self.invoke([
            'security-list', 'update', '--security-list-id', self.sl_ocid,
            '--egress-security-rules', egress_rules_v2
        ],
                             input='n')
        assert result.exit_code != 0

        # update egress-rules, force
        result = self.invoke([
            'security-list', 'update', '--security-list-id', self.sl_ocid,
            '--egress-security-rules', egress_rules_v2, '--force'
        ])
        util.validate_response(result, expect_etag=True)
Example #11
0
    def subtest_delete(self):
        error_count = 0

        if hasattr(self, 'rt_ocid'):
            max_retry = 3
            retry = 0
            try:
                while retry < max_retry:
                    try:
                        util.vcr_mode_aware_sleep(2)
                        result = self.invoke([
                            'route-table', 'delete', '--rt-id', self.rt_ocid,
                            '--force'
                        ])
                        util.validate_response(result)
                        break
                    except Exception as error:
                        # if the route-table no longer exists then don't try to delete it again
                        if '"status": 404' in result.output:
                            break
                        else:
                            retry += 1
                            print("Retrying route-table delete.")

                util.wait_until(
                    ['network', 'route-table', 'get', '--rt-id', self.rt_ocid],
                    'TERMINATED',
                    succeed_if_not_found=True,
                    max_wait_seconds=300)
            except Exception as error:
                util.print_latest_exception(error)
                error_count = error_count + 1

        if hasattr(self, 'ipsc_ocid'):
            try:
                result = self.invoke([
                    'ip-sec-connection', 'delete', '--ipsc-id', self.ipsc_ocid,
                    '--force'
                ])
                util.validate_response(result)
                util.wait_until([
                    'network', 'ip-sec-connection', 'get', '--ipsc-id',
                    self.ipsc_ocid
                ],
                                'TERMINATED',
                                succeed_if_not_found=True,
                                max_wait_seconds=300)
            except Exception as error:
                util.print_latest_exception(error)
                error_count = error_count + 1

        if hasattr(self, 'drg_attachment_ocid'):
            try:
                result = self.invoke([
                    'drg-attachment', 'delete', '--drg-attachment-id',
                    self.drg_attachment_ocid, '--force'
                ])
                util.validate_response(result)
                util.wait_until([
                    'network', 'drg-attachment', 'get', '--drg-attachment-id',
                    self.drg_attachment_ocid
                ],
                                'DETACHED',
                                succeed_if_not_found=True,
                                max_wait_seconds=600)
            except Exception as error:
                util.print_latest_exception(error)
                error_count = error_count + 1

        if hasattr(self, 'drg_ocid'):
            try:
                result = self.invoke(
                    ['drg', 'delete', '--drg-id', self.drg_ocid, '--force'])
                util.validate_response(result)
                util.wait_until(
                    ['network', 'drg', 'get', '--drg-id', self.drg_ocid],
                    'TERMINATED',
                    succeed_if_not_found=True,
                    max_wait_seconds=600)
            except Exception as error:
                util.print_latest_exception(error)
                error_count = error_count + 1

        if hasattr(self, 'dhcp_options_ocid'):
            try:
                result = self.invoke([
                    'dhcp-options', 'delete', '--dhcp-id',
                    self.dhcp_options_ocid, '--force'
                ])
                util.validate_response(result)
                util.wait_until([
                    'network', 'dhcp-options', 'get', '--dhcp-id',
                    self.dhcp_options_ocid
                ],
                                'TERMINATED',
                                succeed_if_not_found=True,
                                max_wait_seconds=600)
            except Exception as error:
                util.print_latest_exception(error)
                error_count = error_count + 1

        if hasattr(self, 'cpe_ocid'):
            try:
                result = self.invoke(
                    ['cpe', 'delete', '--cpe-id', self.cpe_ocid, '--force'])
                util.validate_response(result)
            except Exception as error:
                util.print_latest_exception(error)
                error_count = error_count + 1

        if hasattr(self, 'ig_ocid'):
            try:
                result = self.invoke([
                    'internet-gateway', 'delete', '--ig-id', self.ig_ocid,
                    '--force'
                ])
                util.validate_response(result)
                util.wait_until([
                    'network', 'internet-gateway', 'get', '--ig-id',
                    self.ig_ocid
                ],
                                'TERMINATED',
                                max_wait_seconds=600,
                                succeed_if_not_found=True)
            except Exception as error:
                util.print_latest_exception(error)
                error_count = error_count + 1

        if hasattr(self, 'subnet_ocid'):
            try:
                result = self.invoke([
                    'subnet', 'delete', '--subnet-id', self.subnet_ocid,
                    '--force'
                ])
                util.validate_response(result)
                util.wait_until([
                    'network', 'subnet', 'get', '--subnet-id', self.subnet_ocid
                ],
                                'TERMINATED',
                                max_wait_seconds=600,
                                succeed_if_not_found=True)
            except Exception as error:
                util.print_latest_exception(error)
                error_count = error_count + 1

        if hasattr(self, 'sl_ocid'):
            try:
                result = self.invoke([
                    'security-list', 'delete', '--security-list-id',
                    self.sl_ocid, '--force'
                ])
                util.validate_response(result)
                util.wait_until([
                    'network', 'security-list', 'get', '--security-list-id',
                    self.sl_ocid
                ],
                                'TERMINATED',
                                succeed_if_not_found=True,
                                max_wait_seconds=300)
            except Exception as error:
                util.print_latest_exception(error)
                error_count = error_count + 1

        if hasattr(self, 'vcn_ocid'):
            try:
                result = self.invoke(
                    ['vcn', 'delete', '--vcn-id', self.vcn_ocid, '--force'])
                util.validate_response(result)
            except Exception as error:
                util.print_latest_exception(error)
                error_count = error_count + 1

        self.assertEquals(0, error_count)