def test_put_FetchImageTask(self, mock_put): etcd.put('objecttype', 'subtype', 'name', tasks.FetchImageTask('http://server/image')) path = '/sf/objecttype/subtype/name' encoded = '''{ "instance_uuid": null, "task": "image_fetch", "url": "http://server/image", "version": 1 }''' mock_put.assert_called_with(path, encoded, lease=None) etcd.put( 'objecttype', 'subtype', 'name', tasks.FetchImageTask('http://server/image', instance_uuid='fake_uuid')) path = '/sf/objecttype/subtype/name' encoded = '''{ "instance_uuid": "fake_uuid", "task": "image_fetch", "url": "http://server/image", "version": 1 }''' mock_put.assert_called_with(path, encoded, lease=None)
def test_FetchImageTask(self): with testtools.ExpectedException( exceptions.NoURLImageFetchTaskException): tasks.FetchImageTask(None) with testtools.ExpectedException( exceptions.NoURLImageFetchTaskException): tasks.FetchImageTask(1234)
def test_dequeue_image_fetch(self, m_delete, m_put, m_get_lock, m_get_prefix): jobname, workitem = etcd.dequeue('node01') self.assertEqual('1631269187.890441', jobname) expected = [ tasks.FetchImageTask('http://whoknows', 'fake_uuid'), ] self.assertCountEqual(expected, workitem['tasks']) self.assertSequenceEqual(expected, workitem['tasks'])
def test_QueueTask_eq(self): self.assertEqual(tasks.PreflightInstanceTask('abcd'), tasks.PreflightInstanceTask('abcd')) self.assertEqual(tasks.PreflightInstanceTask('abcd', []), tasks.PreflightInstanceTask('abcd', [])) self.assertEqual(tasks.PreflightInstanceTask('abcd'), tasks.PreflightInstanceTask('abcd', [])) self.assertNotEqual(tasks.PreflightInstanceTask('abcd'), tasks.PreflightInstanceTask('abcd', ['netuuid'])) self.assertEqual(tasks.PreflightInstanceTask('abcd', ['a1', 'b2']), tasks.PreflightInstanceTask('abcd', ['a1', 'b2'])) self.assertNotEqual(tasks.PreflightInstanceTask('abcd', ['a1', 'b2']), tasks.PreflightInstanceTask('abcd', ['a1'])) with testtools.ExpectedException(NotImplementedError): self.assertEqual(tasks.PreflightInstanceTask('abcd', ['a1', 'b2']), 42) self.assertEqual(tasks.DeleteInstanceTask('abcd'), tasks.DeleteInstanceTask('abcd')) self.assertEqual(tasks.ErrorInstanceTask('abcd', 'someExcuse'), tasks.ErrorInstanceTask('abcd', 'someExcuse')) self.assertNotEqual(tasks.ErrorInstanceTask('abcd', 'someExcuse'), tasks.ErrorInstanceTask('abcd', 'something')) self.assertEqual(tasks.ErrorInstanceTask('abcd', 'dunno'), tasks.ErrorInstanceTask('abcd', 'dunno')) self.assertEqual(tasks.ImageTask('http://someurl'), tasks.ImageTask('http://someurl')) self.assertNotEqual(tasks.ImageTask('http://someurl'), tasks.ImageTask('http://someur')) self.assertEqual(tasks.FetchImageTask('http://someurl', 'fake_uuid'), tasks.FetchImageTask('http://someurl', 'fake_uuid')) self.assertNotEqual( tasks.FetchImageTask('http://someurl'), tasks.FetchImageTask('http://someurl', 'fake_uuid')) self.assertNotEqual( tasks.FetchImageTask('http://someurl', 'fake_uuid'), tasks.FetchImageTask('http://someurl', 'fake_uudd')) self.assertNotEqual( tasks.FetchImageTask('http://someurl', 'fake_uuid'), tasks.FetchImageTask('http://someurm', 'fake_uuid'))
def test_decode_multi(self): obs = etcd.decodeTasks({'tasks': [ { 'instance_uuid': 'fake_uuid', 'network': None, 'task': 'instance_preflight', 'version': 1, }, { 'instance_uuid': 'fake_uuid', 'task': 'image_fetch', 'url': 'http://whoknows', 'version': 1, }]}) self.assertItemsEqual( {'tasks': [ tasks.PreflightInstanceTask('fake_uuid'), tasks.FetchImageTask('http://whoknows', 'fake_uuid') ]}, obs)