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()
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()
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()