def test_create_wake_on_lan(self): """ Test if wake on lan works """ mock_sleep = MagicMock() mock_cmd = MagicMock(return_value=True) mm_cmd = MagicMock(return_value={"friend1": True}) lcl = salt.client.LocalClient() lcl.cmd = mm_cmd with patch("time.sleep", mock_sleep): with patch("salt.client.LocalClient", return_value=lcl): with patch.dict("salt.cloud.clouds.saltify.__utils__", {"cloud.bootstrap": mock_cmd}): vm_ = { "deploy": True, "driver": "saltify", "name": "new1", "profile": "testprofile3", } result = saltify.create(vm_) mock_cmd.assert_called_once_with(vm_, ANY) mm_cmd.assert_called_with("friend1", "network.wol", ["aa-bb-cc-dd-ee-ff"]) # The test suite might call time.sleep, look for any call # that has the expected wait time. mock_sleep.assert_any_call(0.01) self.assertTrue(result)
def test_create_wake_on_lan(self): ''' Test if wake on lan works ''' mock_sleep = MagicMock() mock_cmd = MagicMock(return_value=True) mm_cmd = MagicMock(return_value={'friend1': True}) lcl = salt.client.LocalClient() lcl.cmd = mm_cmd with patch('time.sleep', mock_sleep): with patch('salt.client.LocalClient', return_value=lcl): with patch.dict('salt.cloud.clouds.saltify.__utils__', {'cloud.bootstrap': mock_cmd}): vm_ = { 'deploy': True, 'driver': 'saltify', 'name': 'new1', 'profile': 'testprofile3', } result = saltify.create(vm_) mock_cmd.assert_called_once_with(vm_, ANY) mm_cmd.assert_called_with('friend1', 'network.wol', ['aa-bb-cc-dd-ee-ff']) mock_sleep.assert_called_with(0.01) self.assertTrue(result)
def test_create_no_deploy(self): """ Test if deployment fails. This is the most basic test as saltify doesn't contain much logic """ with patch("salt.cloud.clouds.saltify._verify", MagicMock(return_value=True)): vm = {"deploy": False, "driver": "saltify", "name": "dummy"} self.assertTrue(saltify.create(vm))
def test_create_no_deploy(self): ''' Test if deployment fails. This is the most basic test as saltify doesn't contain much logic ''' with patch('salt.cloud.clouds.saltify._verify', MagicMock(return_value=True)): vm = {'deploy': False, 'driver': 'saltify', 'name': 'dummy'} self.assertTrue(saltify.create(vm))
def test_create_no_deploy(self): ''' Test if deployment fails. This is the most basic test as saltify doesn't contain much logic ''' vm = {'deploy': False, 'provider': 'saltify', 'name': 'dummy' } self.assertTrue(saltify.create(vm)['Error']['No Deploy'])
def test_create_no_deploy(self): ''' Test if deployment fails. This is the most basic test as saltify doesn't contain much logic ''' vm = {'deploy': False, 'provider': 'saltify', 'name': 'dummy' } self.assertTrue(saltify.create(vm)['Error']['No Deploy'])
def test_create_and_deploy(self): """ Test if deployment can be done. """ mock_cmd = MagicMock(return_value=True) with patch.dict("salt.cloud.clouds.saltify.__utils__", {"cloud.bootstrap": mock_cmd}): vm_ = { "deploy": True, "driver": "saltify", "name": "new2", "profile": "testprofile2", } result = saltify.create(vm_) mock_cmd.assert_called_once_with(vm_, ANY) self.assertTrue(result)
def test_create_and_deploy(self): ''' Test if deployment can be done. ''' mock_cmd = MagicMock(return_value=True) with patch.dict('salt.cloud.clouds.saltify.__utils__', {'cloud.bootstrap': mock_cmd}): vm_ = { 'deploy': True, 'driver': 'saltify', 'name': 'new2', 'profile': 'testprofile2', } result = saltify.create(vm_) mock_cmd.assert_called_once_with(vm_, ANY) self.assertTrue(result)
def test_create_no_ssh_host(self): """ Test that ssh_host is set to the vm name if not defined """ mock_cmd = MagicMock(return_value=True) with patch.dict("salt.cloud.clouds.saltify.__utils__", {"cloud.bootstrap": mock_cmd}): vm_ = { "deploy": True, "driver": "saltify", "name": "new2", "profile": "testprofile2", } result = saltify.create(vm_) mock_cmd.assert_called_once_with(vm_, ANY) assert result # Make sure that ssh_host was added to the vm. Note that this is # done in two asserts so that the failure is more explicit about # what is wrong. If ssh_host wasn't inserted in the vm_ dict, the # failure would be a KeyError, which would be harder to # troubleshoot. assert "ssh_host" in vm_ assert vm_["ssh_host"] == "new2"