Ejemplo n.º 1
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.º 2
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.º 3
0
    def test_launch_instance(
        self, mock_init, mock_create_vcn, mock_create_subnet,
        mock_create_ig, mock_get_ssh_key, mock_terminate_instance,
        mock_wait_on_instance
    ):
        """Test oci launch instance method."""
        mock_init.return_value = None

        logger = MagicMock()

        vcn = MagicMock()
        mock_create_vcn.return_value = vcn

        instance = MagicMock()
        instance.id = 'instance-123'

        response = MagicMock()
        response.data = instance

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

        subnet = MagicMock()
        subnet.id = 'subnet-123'
        mock_create_subnet.return_value = subnet

        mock_get_ssh_key.return_value = 'key123'

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

        cloud.compartment_id = (
            'ocid1.compartment.oc1..'
            'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
        )
        cloud.availability_domain = 'Omic:PHX-AD-1'
        cloud.timeout = 600
        cloud.subnet_id = None
        cloud.instance_type = None
        cloud.image_id = 'image123'
        cloud.logger = logger
        cloud.prefix_name = None

        cloud._launch_instance()

        # Test exception case
        client.launch_instance.side_effect = Exception('Broken')
        mock_terminate_instance.side_effect = Exception(
            'Cannot terminate instance'
        )

        with pytest.raises(Exception):
            cloud._launch_instance()
Ejemplo n.º 4
0
    def test_oci_create_vcn(self, mock_init):
        """Test oci create vcn method."""
        mock_init.return_value = None

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

        client.create_vcn_and_wait_for_state.return_value = response

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

        result = cloud._create_vcn('vcn-123')
        assert result == vcn