예제 #1
0
    def test_stop_instance(self, mock_init, mock_wait_on_instance):
        """Test oci stop instance method."""
        mock_init.return_value = None

        client = MagicMock()

        cloud = OCICloud(**self.kwargs)
        cloud.compute_client = client
        cloud.running_instance_id = 'instance123'
        cloud.timeout = 600

        cloud._stop_instance()
예제 #2
0
    def test_get_console_log(self, mock_init):
        """Test oci get console log method."""
        mock_init.return_value = None
        response = MagicMock()
        response.data = b'Test output'
        client = MagicMock()
        client.get_console_history_content.return_value = response

        cloud = OCICloud(**self.kwargs)
        cloud.compute_client = client
        cloud.compute_composite_client = client
        cloud.running_instance_id = 'instance-123'

        log = cloud.get_console_log()
        assert log == 'Test output'
예제 #3
0
    def test_oci_is_instance_running(self, mock_init):
        """Test oci is instance running method."""
        mock_init.return_value = None

        client = MagicMock()
        instance = MagicMock()
        instance.lifecycle_state = 'RUNNING'
        response = MagicMock()
        response.data = instance
        client.get_instance.return_value = response

        cloud = OCICloud(**self.kwargs)
        cloud.running_instance_id = 'instance-123'
        cloud.compute_client = client

        result = cloud._is_instance_running()
        assert result
예제 #4
0
    def test_terminate_instance(
        self, mock_init, mock_get_vcn, mock_get_subnet, mock_delete_subnet,
        mock_clear_route_rules, mock_get_gateway, mock_delete_gateway,
        mock_delete_vcn
    ):
        """Test oci terminate instance method."""
        mock_init.return_value = None

        client = MagicMock()

        vcn = MagicMock()
        vcn.id = 'vcn123'
        mock_get_vcn.return_value = vcn

        subnet = MagicMock()
        subnet.id = 'subnet123'
        mock_get_subnet.return_value = subnet

        gateway = MagicMock()
        gateway.id = 'gateway123'
        mock_get_gateway.return_value = gateway

        cloud = OCICloud(**self.kwargs)
        cloud.compute_composite_client = client
        cloud.running_instance_id = 'instance123'
        cloud.display_name = 'oci-ipa-test'
        cloud.timeout = 600

        cloud._terminate_instance()

        # No VCN
        mock_get_vcn.return_value = None
        cloud._terminate_instance()

        # Display name not created by img-proof
        cloud.display_name = 'not-ipa-test'
        cloud._terminate_instance()