Beispiel #1
0
    def test_update_in_place(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)
        queue = self.stack["MyQueue2"]
        queue.resource_id_set(queue.properties.get("name"))
        self.m.StubOutWithMock(queue, "client")
        queue.client().MultipleTimes().AndReturn(self.fc)
        fake_q = FakeQueue("myqueue", auto_create=False)
        self.m.StubOutWithMock(self.fc, "queue")
        self.fc.queue("myqueue", auto_create=False).MultipleTimes().AndReturn(fake_q)
        self.m.StubOutWithMock(fake_q, "metadata")
        fake_q.metadata(new_meta={"key1": {"key2": "value", "key3": [1, 2]}})

        # Expected to be called during update
        fake_q.metadata(new_meta={"key1": "value"})

        self.m.ReplayAll()

        t = template_format.parse(wp_template)
        new_queue = t["Resources"]["MyQueue2"]
        new_queue["Properties"]["metadata"] = {"key1": "value"}
        resource_defns = template.Template(t).resource_definitions(self.stack)

        scheduler.TaskRunner(queue.create)()
        scheduler.TaskRunner(queue.update, resource_defns["MyQueue2"])()
        self.m.VerifyAll()
Beispiel #2
0
    def test_show_resource(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)

        queue = self.stack['MyQueue2']
        self.m.StubOutWithMock(queue, 'client')
        queue.client().MultipleTimes().AndReturn(self.fc)

        fake_q = FakeQueue(queue.physical_resource_name(), auto_create=False)
        self.m.StubOutWithMock(self.fc, 'queue')
        self.fc.queue(queue.physical_resource_name(),
                      auto_create=False).AndReturn(fake_q)
        self.m.StubOutWithMock(fake_q, 'metadata')
        fake_q.metadata(new_meta=queue.properties.get('metadata'))
        self.fc.queue(queue.physical_resource_name(),
                      auto_create=False).AndReturn(fake_q)
        fake_q.metadata().AndReturn(
            {"key1": {
                "key2": "value",
                "key3": [1, 2]
            }})
        self.m.ReplayAll()

        scheduler.TaskRunner(queue.create)()
        self.assertEqual(
            {'metadata': {
                "key1": {
                    "key2": "value",
                    "key3": [1, 2]
                }
            }}, queue._show_resource())

        self.m.VerifyAll()
Beispiel #3
0
    def test_create(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)

        queue = self.stack['MyQueue2']
        self.m.StubOutWithMock(queue, 'client')
        queue.client().MultipleTimes().AndReturn(self.fc)

        fake_q = FakeQueue(queue.physical_resource_name(), auto_create=False)
        self.m.StubOutWithMock(self.fc, 'queue')
        self.fc.queue(queue.physical_resource_name(),
                      auto_create=False).AndReturn(fake_q)
        self.m.StubOutWithMock(fake_q, 'exists')
        fake_q.exists().AndReturn(False)
        self.m.StubOutWithMock(fake_q, 'ensure_exists')
        fake_q.ensure_exists()
        self.fc.queue(queue.physical_resource_name(),
                      auto_create=False).AndReturn(fake_q)
        fake_q.exists().AndReturn(True)
        self.m.StubOutWithMock(fake_q, 'metadata')
        fake_q.metadata(new_meta=queue.properties.get('metadata'))

        self.m.ReplayAll()

        scheduler.TaskRunner(queue.create)()
        self.fc.api_url = 'http://127.0.0.1:8888/v1'
        self.assertEqual('http://127.0.0.1:8888/v1/queues/myqueue',
                         queue.FnGetAtt('href'))

        self.m.VerifyAll()
Beispiel #4
0
    def test_create_default_name(self):
        t = template_format.parse(wp_template)
        del t["Resources"]["MyQueue2"]["Properties"]["name"]
        self.parse_stack(t)

        queue = self.stack["MyQueue2"]
        self.m.StubOutWithMock(queue, "client")
        queue.client().MultipleTimes().AndReturn(self.fc)

        name_match = utils.PhysName(self.stack.name, "MyQueue2")
        self.m.StubOutWithMock(self.fc, "queue")
        self.fc.queue(name_match, auto_create=False).WithSideEffects(FakeQueue)

        self.m.ReplayAll()

        scheduler.TaskRunner(queue.create)()

        queue_name = queue.physical_resource_name()
        self.assertEqual(name_match, queue_name)

        self.fc.api_url = "http://127.0.0.1:8888"
        self.fc.api_version = 2
        self.assertEqual("http://127.0.0.1:8888/v2/queues/" + queue_name, queue.FnGetAtt("href"))

        self.m.VerifyAll()
Beispiel #5
0
    def test_update_in_place(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)
        queue = self.stack['MyQueue2']
        queue.resource_id_set(queue.properties.get('name'))
        self.m.StubOutWithMock(queue, 'client')
        queue.client().MultipleTimes().AndReturn(self.fc)
        fake_q = FakeQueue('myqueue', auto_create=False)
        self.m.StubOutWithMock(self.fc, 'queue')
        self.fc.queue('myqueue',
                      auto_create=False).MultipleTimes().AndReturn(fake_q)
        self.m.StubOutWithMock(fake_q, 'metadata')
        fake_q.metadata(new_meta={"key1": {"key2": "value", "key3": [1, 2]}})

        # Expected to be called during update
        fake_q.metadata(new_meta={'key1': 'value'})

        self.m.ReplayAll()

        t = template_format.parse(wp_template)
        new_queue = t['Resources']['MyQueue2']
        new_queue['Properties']['metadata'] = {'key1': 'value'}
        resource_defns = template.Template(t).resource_definitions(self.stack)

        scheduler.TaskRunner(queue.create)()
        scheduler.TaskRunner(queue.update, resource_defns['MyQueue2'])()
        self.m.VerifyAll()
Beispiel #6
0
    def test_update_replace(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)
        queue = self.stack['MyQueue2']
        queue.resource_id_set(queue.properties.get('name'))
        self.m.StubOutWithMock(queue, 'client')
        queue.client().MultipleTimes().AndReturn(self.fc)
        fake_q = FakeQueue('myqueue', auto_create=False)
        self.m.StubOutWithMock(self.fc, 'queue')
        self.fc.queue('myqueue',
                      auto_create=False).MultipleTimes().AndReturn(fake_q)

        self.m.ReplayAll()

        t = template_format.parse(wp_template)
        t['Resources']['MyQueue2']['Properties']['name'] = 'new_queue'
        resource_defns = template.Template(t).resource_definitions(self.stack)
        new_queue = resource_defns['MyQueue2']

        scheduler.TaskRunner(queue.create)()
        err = self.assertRaises(resource.UpdateReplace,
                                scheduler.TaskRunner(queue.update, new_queue))
        msg = 'The Resource MyQueue2 requires replacement.'
        self.assertEqual(msg, six.text_type(err))

        self.m.VerifyAll()
Beispiel #7
0
    def test_create_failed(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)

        queue = self.stack['MyQueue2']
        self.m.StubOutWithMock(queue, 'client')
        queue.client().MultipleTimes().AndReturn(self.fc)

        fake_q = FakeQueue("myqueue", auto_create=False)
        self.m.StubOutWithMock(self.fc, 'queue')
        self.fc.queue("myqueue", auto_create=False).AndReturn(fake_q)
        self.m.StubOutWithMock(fake_q, 'exists')
        fake_q.exists().AndReturn(False)
        self.m.StubOutWithMock(fake_q, 'ensure_exists')
        self.fc.queue(queue.physical_resource_name(),
                      auto_create=False).AndReturn(fake_q)
        fake_q.ensure_exists()
        fake_q.exists().AndReturn(False)

        self.m.ReplayAll()

        err = self.assertRaises(exception.ResourceFailure,
                                scheduler.TaskRunner(queue.create))
        self.assertEqual(
            "Error: resources.MyQueue2: "
            "Message queue myqueue creation failed.", six.text_type(err))
        self.m.VerifyAll()
Beispiel #8
0
    def test_update_replace(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)
        queue = self.stack['MyQueue2']
        queue.resource_id_set(queue.properties.get('name'))
        self.m.StubOutWithMock(queue, 'client')
        queue.client().MultipleTimes().AndReturn(self.fc)
        fake_q = FakeQueue('myqueue', auto_create=False)
        self.m.StubOutWithMock(self.fc, 'queue')
        self.fc.queue('myqueue',
                      auto_create=False).MultipleTimes().AndReturn(fake_q)

        self.m.ReplayAll()

        t = template_format.parse(wp_template)
        t['Resources']['MyQueue2']['Properties']['name'] = 'new_queue'
        resource_defns = template.Template(t).resource_definitions(self.stack)
        new_queue = resource_defns['MyQueue2']

        scheduler.TaskRunner(queue.create)()
        err = self.assertRaises(resource.UpdateReplace,
                                scheduler.TaskRunner(queue.update,
                                                     new_queue))
        msg = 'The Resource MyQueue2 requires replacement.'
        self.assertEqual(msg, six.text_type(err))

        self.m.VerifyAll()
Beispiel #9
0
    def test_create(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)

        queue = self.stack['MyQueue2']
        self.m.StubOutWithMock(queue, 'client')
        queue.client().MultipleTimes().AndReturn(self.fc)

        fake_q = FakeQueue(queue.physical_resource_name(), auto_create=False)
        self.m.StubOutWithMock(self.fc, 'queue')
        self.fc.queue(queue.physical_resource_name(),
                      auto_create=False).AndReturn(fake_q)
        self.m.StubOutWithMock(fake_q, 'exists')
        fake_q.exists().AndReturn(False)
        self.m.StubOutWithMock(fake_q, 'ensure_exists')
        fake_q.ensure_exists()
        self.fc.queue(queue.physical_resource_name(),
                      auto_create=False).AndReturn(fake_q)
        fake_q.exists().AndReturn(True)
        self.m.StubOutWithMock(fake_q, 'metadata')
        fake_q.metadata(new_meta=queue.properties.get('metadata'))

        self.m.ReplayAll()

        scheduler.TaskRunner(queue.create)()
        self.fc.api_url = 'http://127.0.0.1:8888/v1'
        self.assertEqual('http://127.0.0.1:8888/v1/queues/myqueue',
                         queue.FnGetAtt('href'))

        self.m.VerifyAll()
Beispiel #10
0
    def test_create_failed(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)

        queue = self.stack['MyQueue2']
        self.m.StubOutWithMock(queue, 'client')
        queue.client().MultipleTimes().AndReturn(self.fc)

        fake_q = FakeQueue("myqueue", auto_create=False)
        self.m.StubOutWithMock(self.fc, 'queue')
        self.fc.queue("myqueue", auto_create=False).AndReturn(fake_q)
        self.m.StubOutWithMock(fake_q, 'exists')
        fake_q.exists().AndReturn(False)
        self.m.StubOutWithMock(fake_q, 'ensure_exists')
        self.fc.queue(queue.physical_resource_name(),
                      auto_create=False).AndReturn(fake_q)
        fake_q.ensure_exists()
        fake_q.exists().AndReturn(False)

        self.m.ReplayAll()

        err = self.assertRaises(exception.ResourceFailure,
                                scheduler.TaskRunner(queue.create))
        self.assertEqual("Error: resources.MyQueue2: "
                         "Message queue myqueue creation failed.",
                         six.text_type(err))
        self.m.VerifyAll()
Beispiel #11
0
    def test_update_in_place(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)
        queue = self.stack['MyQueue2']
        queue.resource_id_set(queue.properties.get('name'))
        self.m.StubOutWithMock(queue, 'client')
        queue.client().MultipleTimes().AndReturn(self.fc)
        fake_q = FakeQueue('myqueue', auto_create=False)
        self.m.StubOutWithMock(self.fc, 'queue')
        self.fc.queue('myqueue',
                      auto_create=False).MultipleTimes().AndReturn(fake_q)
        self.m.StubOutWithMock(fake_q, 'metadata')
        fake_q.metadata(new_meta={"key1": {"key2": "value", "key3": [1, 2]}})

        # Expected to be called during update
        fake_q.metadata(new_meta={'key1': 'value'})

        self.m.ReplayAll()

        t = template_format.parse(wp_template)
        new_queue = t['Resources']['MyQueue2']
        new_queue['Properties']['metadata'] = {'key1': 'value'}
        resource_defns = template.Template(t).resource_definitions(self.stack)

        scheduler.TaskRunner(queue.create)()
        scheduler.TaskRunner(queue.update, resource_defns['MyQueue2'])()
        self.m.VerifyAll()
Beispiel #12
0
    def test_create_default_name(self):
        t = template_format.parse(wp_template)
        del t['Resources']['MyQueue2']['Properties']['name']
        self.parse_stack(t)

        queue = self.stack['MyQueue2']
        self.m.StubOutWithMock(queue, 'client')
        queue.client().MultipleTimes().AndReturn(self.fc)

        name_match = utils.PhysName(self.stack.name, 'MyQueue2')
        self.m.StubOutWithMock(self.fc, 'queue')
        self.fc.queue(name_match, auto_create=False).WithSideEffects(FakeQueue)

        self.m.ReplayAll()

        scheduler.TaskRunner(queue.create)()

        queue_name = queue.physical_resource_name()
        self.assertEqual(name_match, queue_name)

        self.fc.api_url = 'http://127.0.0.1:8888'
        self.fc.api_version = 2
        self.assertEqual('http://127.0.0.1:8888/v2/queues/' + queue_name,
                         queue.FnGetAtt('href'))

        self.m.VerifyAll()
Beispiel #13
0
    def test_parse_live_resource_data(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)

        queue = self.stack['MyQueue2']
        self.m.StubOutWithMock(queue, 'client')
        queue.client().MultipleTimes().AndReturn(self.fc)

        fake_q = FakeQueue(queue.physical_resource_name(), auto_create=False)
        self.m.StubOutWithMock(self.fc, 'queue')
        self.fc.queue(queue.physical_resource_name(),
                      auto_create=False).AndReturn(fake_q)
        self.m.StubOutWithMock(fake_q, 'metadata')
        fake_q.metadata(new_meta=queue.properties.get('metadata'))
        self.fc.queue(queue.physical_resource_name(),
                      auto_create=False).AndReturn(fake_q)
        fake_q.metadata().AndReturn(
            {"key1": {"key2": "value", "key3": [1, 2]}})
        self.m.ReplayAll()

        scheduler.TaskRunner(queue.create)()
        self.assertEqual(
            {'metadata': {"key1": {"key2": "value", "key3": [1, 2]}},
             'name': queue.resource_id},
            queue.parse_live_resource_data(queue.properties,
                                           queue._show_resource()))

        self.m.VerifyAll()
Beispiel #14
0
    def test_create_default_name(self):
        t = template_format.parse(wp_template)
        del t['Resources']['MyQueue2']['Properties']['name']
        self.parse_stack(t)

        queue = self.stack['MyQueue2']
        self.m.StubOutWithMock(queue, 'client')
        queue.client().MultipleTimes().AndReturn(self.fc)

        name_match = utils.PhysName(self.stack.name, 'MyQueue2')
        self.m.StubOutWithMock(self.fc, 'queue')
        self.fc.queue(name_match, auto_create=False).WithSideEffects(FakeQueue)

        self.m.ReplayAll()

        scheduler.TaskRunner(queue.create)()

        queue_name = queue.physical_resource_name()
        self.assertEqual(name_match, queue_name)

        self.fc.api_url = 'http://127.0.0.1:8888'
        self.fc.api_version = 2
        self.assertEqual('http://127.0.0.1:8888/v2/queues/' + queue_name,
                         queue.FnGetAtt('href'))

        self.m.VerifyAll()
Beispiel #15
0
    def test_delete(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)

        queue = self.stack["MyQueue2"]
        queue.resource_id_set(queue.properties.get("name"))
        self.m.StubOutWithMock(queue, "client")
        queue.client().MultipleTimes().AndReturn(self.fc)

        fake_q = FakeQueue("myqueue", auto_create=False)
        self.m.StubOutWithMock(self.fc, "queue")
        self.fc.queue("myqueue", auto_create=False).MultipleTimes().AndReturn(fake_q)
        self.m.StubOutWithMock(fake_q, "delete")
        fake_q.delete()

        self.m.ReplayAll()

        scheduler.TaskRunner(queue.create)()
        scheduler.TaskRunner(queue.delete)()
        self.m.VerifyAll()
Beispiel #16
0
    def test_delete(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)

        queue = self.stack['MyQueue2']
        queue.resource_id_set(queue.properties.get('name'))
        self.m.StubOutWithMock(queue, 'client')
        queue.client().MultipleTimes().AndReturn(self.fc)

        fake_q = FakeQueue("myqueue", auto_create=False)
        self.m.StubOutWithMock(self.fc, 'queue')
        self.fc.queue("myqueue",
                      auto_create=False).MultipleTimes().AndReturn(fake_q)
        self.m.StubOutWithMock(fake_q, 'delete')
        fake_q.delete()

        self.m.ReplayAll()

        scheduler.TaskRunner(queue.create)()
        scheduler.TaskRunner(queue.delete)()
        self.m.VerifyAll()
Beispiel #17
0
    def test_show_resource(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)

        queue = self.stack["MyQueue2"]
        self.m.StubOutWithMock(queue, "client")
        queue.client().MultipleTimes().AndReturn(self.fc)

        fake_q = FakeQueue(queue.physical_resource_name(), auto_create=False)
        self.m.StubOutWithMock(self.fc, "queue")
        self.fc.queue(queue.physical_resource_name(), auto_create=False).AndReturn(fake_q)
        self.m.StubOutWithMock(fake_q, "metadata")
        fake_q.metadata(new_meta=queue.properties.get("metadata"))
        self.fc.queue(queue.physical_resource_name(), auto_create=False).AndReturn(fake_q)
        fake_q.metadata().AndReturn({"key1": {"key2": "value", "key3": [1, 2]}})
        self.m.ReplayAll()

        scheduler.TaskRunner(queue.create)()
        self.assertEqual({"metadata": {"key1": {"key2": "value", "key3": [1, 2]}}}, queue._show_resource())

        self.m.VerifyAll()
Beispiel #18
0
    def test_create(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)

        queue = self.stack["MyQueue2"]
        self.m.StubOutWithMock(queue, "client")
        queue.client().MultipleTimes().AndReturn(self.fc)

        fake_q = FakeQueue(queue.physical_resource_name(), auto_create=False)
        self.m.StubOutWithMock(self.fc, "queue")
        self.fc.queue(queue.physical_resource_name(), auto_create=False).AndReturn(fake_q)
        self.m.StubOutWithMock(fake_q, "metadata")
        fake_q.metadata(new_meta=queue.properties.get("metadata"))

        self.m.ReplayAll()

        scheduler.TaskRunner(queue.create)()
        self.fc.api_url = "http://127.0.0.1:8888/"
        self.fc.api_version = 1.1
        self.assertEqual("http://127.0.0.1:8888/v1.1/queues/myqueue", queue.FnGetAtt("href"))

        self.m.VerifyAll()
Beispiel #19
0
    def test_update_replace(self):
        t = template_format.parse(wp_template)
        self.parse_stack(t)
        queue = self.stack["MyQueue2"]
        queue.resource_id_set(queue.properties.get("name"))
        self.m.StubOutWithMock(queue, "client")
        queue.client().MultipleTimes().AndReturn(self.fc)
        fake_q = FakeQueue("myqueue", auto_create=False)
        self.m.StubOutWithMock(self.fc, "queue")
        self.fc.queue("myqueue", auto_create=False).MultipleTimes().AndReturn(fake_q)

        self.m.ReplayAll()

        t = template_format.parse(wp_template)
        t["Resources"]["MyQueue2"]["Properties"]["name"] = "new_queue"
        resource_defns = template.Template(t).resource_definitions(self.stack)
        new_queue = resource_defns["MyQueue2"]

        scheduler.TaskRunner(queue.create)()
        err = self.assertRaises(resource.UpdateReplace, scheduler.TaskRunner(queue.update, new_queue))
        msg = "The Resource MyQueue2 requires replacement."
        self.assertEqual(msg, six.text_type(err))

        self.m.VerifyAll()