Ejemplo n.º 1
0
    def test_set_instance_ip(self, mock_init, mock_get_instance,
                             mock_get_vnic_attachments):
        """Test oci set instance ip method."""
        mock_init.return_value = None

        instance = MagicMock()
        instance.id = 'instance123'
        instance.compartment_id = (
            'ocid1.compartment.oc1..'
            'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')

        attachment = MagicMock()
        attachment.vnic_id = 'vnic123'

        mock_get_vnic_attachments.return_value = [attachment]

        vnic = MagicMock()
        vnic.public_ip = '0.0.0.0'
        vnic.private_ip = '10.0.0.123'

        response = MagicMock()
        response.data = vnic

        client = MagicMock()
        client.get_vnic.return_value = response

        mock_get_instance.return_value = instance

        cloud = OCICloud(**self.kwargs)
        cloud.vnet_client = client

        cloud._set_instance_ip()
Ejemplo n.º 2
0
    def test_oci_get_subnet_by_name(self, mock_init, mock_oci):
        """Test oci get subnet by name method."""
        mock_init.return_value = None

        client = MagicMock()
        subnet = MagicMock()
        subnet.display_name = 'subnet-123'
        response = MagicMock()
        response.data = [subnet]

        mock_oci.pagination.list_call_get_all_results.return_value = response

        cloud = OCICloud(**self.kwargs)
        cloud.compartment_id = (
            'ocid1.compartment.oc1..'
            'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
        )
        cloud.vnet_client = client

        vcn_id = (
            'ocid1.vcn.oc1..'
            'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
        )

        result = cloud._get_subnet_by_name('subnet-123', vcn_id)
        assert result == subnet
Ejemplo n.º 3
0
    def test_oci_get_internet_gateway_by_name(self, mock_init, mock_oci):
        """Test oci get internet gateway by name method."""
        mock_init.return_value = None

        gateway = MagicMock()
        gateway.display_name = 'test-gw2'
        client = MagicMock()
        response = MagicMock()
        response.data = [gateway]

        mock_oci.pagination.list_call_get_all_results.return_value = response

        vcn_id = (
            'ocid1.vcn.oc1..'
            'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
        )

        cloud = OCICloud(**self.kwargs)
        cloud.vnet_client = client
        cloud.compartment_id = (
            'ocid1.compartment.oc1..'
            'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
        )

        result = cloud._get_gateway_in_vcn_by_name(vcn_id, 'test-gw2')
        assert result == gateway
Ejemplo n.º 4
0
    def test_oci_create_internet_gateway(self, mock_init):
        """Test oci create internet gateway method."""
        mock_init.return_value = None

        client = MagicMock()
        vcn = MagicMock()
        route_table = MagicMock()

        vcn.id = (
            'ocid1.vcn.oc1..'
            'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
        )
        vcn.default_route_table_id = (
            'ocid1.routeTable.oc1..'
            'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
        )

        gateway = MagicMock()
        gateway.id = (
            'ocid1.gateway.oc1..'
            'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
        )

        gateway_response = MagicMock()
        gateway_response.data = gateway
        client.create_internet_gateway_and_wait_for_state.return_value = gateway_response  # noqa

        route_table_response = MagicMock()
        route_table_response.data = route_table
        route_table.route_rules = []
        client.get_route_table.return_value = route_table_response

        update_table_response = MagicMock()
        update_table_response.data = []
        client.update_route_table_and_wait_for_state.return_value = update_table_response  # noqa

        cloud = OCICloud(**self.kwargs)
        cloud.vnet_composite_client = client
        cloud.vnet_client = client

        compartment_id = (
            'ocid1.compartment.oc1..'
            'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
        )
        cloud._create_internet_gateway(compartment_id, vcn, 'test-name')
Ejemplo n.º 5
0
    def test_oci_get_subnet(self, mock_init):
        """Test oci get subnet method."""
        mock_init.return_value = None

        client = MagicMock()
        subnet = MagicMock()
        response = MagicMock()
        response.data = subnet

        client.get_subnet.return_value = response

        cloud = OCICloud(**self.kwargs)
        cloud.vnet_client = client

        subnet_id = (
            'ocid1.subnet.oc1..'
            'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')

        result = cloud._get_subnet(subnet_id)
        assert result == subnet
Ejemplo n.º 6
0
    def test_oci_get_vcn(self, mock_init):
        """Test oci get vcn method."""
        mock_init.return_value = None

        client = MagicMock()
        vcn = MagicMock()
        response = MagicMock()
        response.data = vcn

        client.get_vcn.return_value = response

        cloud = OCICloud(**self.kwargs)
        cloud.vnet_client = client

        vcn_id = (
            'ocid1.vcn.oc1..'
            'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')

        result = cloud._get_vcn(vcn_id)
        assert result == vcn