def test_action_do(self, mj): mj.return_value = '{"Action queued with id": "some-action-id"}' d = Deployment(juju_env='gojuju') d.add('mysql') uuid = d.action_do('mysql/0', 'run') self.assertEquals(uuid, "some-action-id") mj.assert_has_calls([call(['action', 'do', 'mysql/0', 'run', '--format', 'json'])])
def test_action_fetch_wait(self, mj): mj.side_effect = [ '{"Action queued with id": "some-action-id"}', '{"results":{"key":"value"},"status":"completed",' '"timing":{"completed":"2015-07-21 09:05:11 +0300 EEST",' '"enqueued":"2015-07-21 09:05:06 +0300 EEST",' '"started":"2015-07-21 09:05:09 +0300 EEST"}}' ] d = Deployment(juju_env='gojuju') d.add('mysql') uuid = d.action_do('mysql/0', 'run') self.assertEquals(uuid, "some-action-id") results = d.action_fetch(uuid) self.assertEquals(results, {'key': 'value'}) if JUJU_VERSION.major == 1: mj.assert_has_calls([ call(['action', 'do', 'mysql/0', 'run', '--format', 'json']), call([ 'action', 'fetch', 'some-action-id', '--format', 'json', '--wait', '600' ]) ]) else: mj.assert_has_calls([ call(['run-action', 'mysql/0', 'run', '--format', 'json']), call([ 'show-action-output', 'some-action-id', '--format', 'json', '--wait', '600' ]) ])
def test_action_fetch_nowait_fail(self, mj): mj.side_effect = [ '{"Action queued with id": "some-action-id"}', '{"status":"running",' '"timing":{"enqueued":"2015-07-21 09:50:59 +0300 EEST",' '"started":"2015-07-21 09:51:04 +0300 EEST"}}' ] d = Deployment(juju_env='gojuju') d.add('mysql') uuid = d.action_do('mysql/0', 'run') self.assertEquals(uuid, "some-action-id") results = d.action_fetch(uuid, timeout=None) self.assertEquals(results, {}) if JUJU_VERSION.major == 1: mj.assert_has_calls([ call(['action', 'do', 'mysql/0', 'run', '--format', 'json']), call(['action', 'fetch', 'some-action-id', '--format', 'json']) ]) else: mj.assert_has_calls([ call(['run-action', 'mysql/0', 'run', '--format', 'json']), call([ 'show-action-output', 'some-action-id', '--format', 'json' ]) ])
def test_action_do(self, mj): mj.return_value = '{"Action queued with id": "some-action-id"}' d = Deployment(juju_env='gojuju') d.add('mysql') uuid = d.action_do('mysql/0', 'run') self.assertEquals(uuid, "some-action-id") mj.assert_has_calls( [call(['action', 'do', 'mysql/0', 'run', '--format', 'json'])])
def test_action_fetch_raise_on_timeout(self, mj): mj.side_effect = ['{"Action queued with id": "some-action-id"}', '{"status":"running",' '"timing":{"enqueued":"2015-07-21 09:50:59 +0300 EEST",' '"started":"2015-07-21 09:51:04 +0300 EEST"}}'] d = Deployment(juju_env='gojuju') d.add('mysql') uuid = d.action_do('mysql/0', 'run') with self.assertRaises(TimeoutError): d.action_fetch(uuid, timeout=None, raise_on_timeout=True)
def test_action_fetch_full_output(self, mj): action_output = ['{"Action queued with id": "some-action-id"}', '{"results":{"key":"value"},"status":"completed",' '"timing":{"completed":"2015-07-21 09:05:11 +0300 EEST",' '"enqueued":"2015-07-21 09:05:06 +0300 EEST",' '"started":"2015-07-21 09:05:09 +0300 EEST"}}'] mj.side_effect = action_output d = Deployment(juju_env='gojuju') d.add('mysql') uuid = d.action_do('mysql/0', 'run') results = d.action_fetch(uuid, full_output=True) self.assertEquals(results, json.loads(action_output[1]))
def test_action_fetch_raise_on_timeout(self, mj): mj.side_effect = [ '{"Action queued with id": "some-action-id"}', '{"status":"running",' '"timing":{"enqueued":"2015-07-21 09:50:59 +0300 EEST",' '"started":"2015-07-21 09:51:04 +0300 EEST"}}' ] d = Deployment(juju_env='gojuju') d.add('mysql') uuid = d.action_do('mysql/0', 'run') with self.assertRaises(TimeoutError): d.action_fetch(uuid, timeout=None, raise_on_timeout=True)
def test_action_fetch_nowait_fail(self, mj): mj.side_effect = ['{"Action queued with id": "some-action-id"}', '{"status":"running",' '"timing":{"enqueued":"2015-07-21 09:50:59 +0300 EEST",' '"started":"2015-07-21 09:51:04 +0300 EEST"}}'] d = Deployment(juju_env='gojuju') d.add('mysql') uuid = d.action_do('mysql/0', 'run') self.assertEquals(uuid, "some-action-id") results = d.action_fetch(uuid, timeout=None) self.assertEquals(results, {}) mj.assert_has_calls([call(['action', 'do', 'mysql/0', 'run', '--format', 'json']), call(['action', 'fetch', 'some-action-id', '--format', 'json'])])
def test_action_fetch_wait(self, mj): mj.side_effect = ['{"Action queued with id": "some-action-id"}', '{"results":{"key":"value"},"status":"completed",' '"timing":{"completed":"2015-07-21 09:05:11 +0300 EEST",' '"enqueued":"2015-07-21 09:05:06 +0300 EEST",' '"started":"2015-07-21 09:05:09 +0300 EEST"}}'] d = Deployment(juju_env='gojuju') d.add('mysql') uuid = d.action_do('mysql/0', 'run') self.assertEquals(uuid, "some-action-id") results = d.action_fetch(uuid) self.assertEquals(results, {'key': 'value'}) mj.assert_has_calls([call(['action', 'do', 'mysql/0', 'run', '--format', 'json']), call(['action', 'fetch', 'some-action-id', '--format', 'json', '--wait', '600'])])
def test_action_fetch_full_output(self, mj): action_output = [ '{"Action queued with id": "some-action-id"}', '{"results":{"key":"value"},"status":"completed",' '"timing":{"completed":"2015-07-21 09:05:11 +0300 EEST",' '"enqueued":"2015-07-21 09:05:06 +0300 EEST",' '"started":"2015-07-21 09:05:09 +0300 EEST"}}' ] mj.side_effect = action_output d = Deployment(juju_env='gojuju') d.add('mysql') uuid = d.action_do('mysql/0', 'run') results = d.action_fetch(uuid, full_output=True) self.assertEquals(results, json.loads(action_output[1]))