  def testGetOrCreateAnalysisVm(self,
                                mock_vm,
                                mock_nic,
                                mock_instance_type,
                                mock_get_instance,
                                mock_script,
                                mock_ssh_parse,
                                mock_provider):
    """Test that a VM is created or retrieved if it already exists."""
    mock_provider.return_value = azure_mocks.MOCK_CAPACITY_PROVIDER
    mock_instance_type.return_value = 'fake-instance-type'
    mock_nic.return_value = 'fake-network-interface-id'
    mock_get_instance.return_value = azure_mocks.FAKE_INSTANCE
    mock_script.return_value = ''
    mock_ssh_parse.return_value = None

    vm, created = azure_mocks.FAKE_ACCOUNT.compute.GetOrCreateAnalysisVm(
        azure_mocks.FAKE_INSTANCE.name, 1, 4, 8192, '')
    mock_get_instance.assert_called_with(azure_mocks.FAKE_INSTANCE.name)
    mock_vm.assert_not_called()
    self.assertIsInstance(vm, compute.AZComputeVirtualMachine)
    self.assertEqual('fake-vm-name', vm.name)
    self.assertFalse(created)

    # We mock the GetInstance() call to throw a ResourceNotFoundError to mimic
    # an instance that wasn't found. This should trigger a vm to be
    # created.
    mock_get_instance.side_effect = errors.ResourceNotFoundError('', __name__)
    mock_vm.return_value.result.return_value = azure_mocks.MOCK_ANALYSIS_INSTANCE
    vm, created = azure_mocks.FAKE_ACCOUNT.compute.GetOrCreateAnalysisVm(
        'fake-analysis-vm-name', 1, 4, 8192, '')
    mock_get_instance.assert_called_with('fake-analysis-vm-name')
    mock_vm.assert_called()
    self.assertIsInstance(vm, compute.AZComputeVirtualMachine)
    self.assertEqual('fake-analysis-vm-name', vm.name)
    self.assertTrue(created)
Test that a VM is created or retrieved if it already exists.
tests/providers/azure/internal/test_compute.py