Example #1
0
    def test_success(self):
        """
        The data is returned as a tuple of ([NovaServer], [CLBNode/RCv3Node]).
        """
        clb_nodes = [CLBNode(node_id='node1', address='ip1',
                             description=CLBDescription(lb_id='lb1', port=80))]
        rcv3_nodes = [RCv3Node(node_id='node2', cloud_server_id='a',
                               description=RCv3Description(lb_id='lb2'))]

        eff = get_all_launch_server_data(
            'tid',
            'gid',
            self.now,
            get_scaling_group_servers=_constant_as_eff(
                ('tid', 'gid', self.now), self.servers),
            get_clb_contents=_constant_as_eff((), clb_nodes),
            get_rcv3_contents=_constant_as_eff((), rcv3_nodes))

        expected_servers = [
            server('a', ServerState.ACTIVE, servicenet_address='10.0.0.1',
                   links=freeze([{'href': 'link1', 'rel': 'self'}]),
                   json=freeze(self.servers[0])),
            server('b', ServerState.ACTIVE, created=1,
                   servicenet_address='10.0.0.2',
                   links=freeze([{'href': 'link2', 'rel': 'self'}]),
                   json=freeze(self.servers[1]))
        ]
        self.assertEqual(resolve_stubs(eff),
                         {'servers': expected_servers,
                          'lb_nodes': clb_nodes + rcv3_nodes})
Example #2
0
 def test_add_json_response(self):
     """The produced request function results in a parsed data structure."""
     response = stub_pure_response('{"a": "b"}', 200)
     request_ = add_json_response(stub_request(response))
     self.assertEqual(resolve_stubs(request_('m', 'u')), (response[0], {
         'a': 'b'
     }))
Example #3
0
    def test_success(self):
        """
        The data is returned as a tuple of ([NovaServer], [CLBNode/RCv3Node]).
        """
        clb_nodes = [CLBNode(node_id='node1', address='ip1',
                             description=CLBDescription(lb_id='lb1', port=80))]
        rcv3_nodes = [RCv3Node(node_id='node2', cloud_server_id='a',
                               description=RCv3Description(lb_id='lb2'))]

        eff = get_all_launch_server_data(
            'tid',
            'gid',
            self.now,
            get_scaling_group_servers=_constant_as_eff(
                ('tid', 'gid', self.now), self.servers),
            get_clb_contents=_constant_as_eff((), clb_nodes),
            get_rcv3_contents=_constant_as_eff((), rcv3_nodes))

        expected_servers = [
            server('a', ServerState.ACTIVE, servicenet_address='10.0.0.1',
                   links=freeze([{'href': 'link1', 'rel': 'self'}]),
                   json=freeze(self.servers[0])),
            server('b', ServerState.ACTIVE, created=1,
                   servicenet_address='10.0.0.2',
                   links=freeze([{'href': 'link2', 'rel': 'self'}]),
                   json=freeze(self.servers[1]))
        ]
        self.assertEqual(resolve_stubs(eff),
                         {'servers': expected_servers,
                          'lb_nodes': clb_nodes + rcv3_nodes})
Example #4
0
 def test_add_headers_optional(self):
     """It's okay if no headers are passed."""
     request_ = add_headers({'one': '1'}, request)
     eff = request_('m', 'u')
     self.assertEqual(
         resolve_stubs(eff).intent,
         Request(method='m', url='u', headers={'one': '1'}))
Example #5
0
 def test_add_headers_optional(self):
     """It's okay if no headers are passed."""
     request_ = add_effectful_headers(self.auth_effect, request)
     eff = request_('m', 'u')
     self.assertEqual(
         resolve_stubs(eff).intent,
         Request(method='m', url='u', headers={'x-auth-token': 'abc123'}))
Example #6
0
 def test_added_headers_win(self):
     """When merging headers together, headers from the effect win."""
     request_ = add_effectful_headers(self.auth_effect, request)
     eff = request_('m', 'u', headers={'x-auth-token': 'fooey'})
     self.assertEqual(
         resolve_stubs(eff).intent,
         Request(method="m", url="u", headers={"x-auth-token": "abc123"}))
Example #7
0
    def test_success(self):
        """
        The data is returned as a tuple of ([NovaServer], [CLBNode/RCv3Node]).
        """
        clb_nodes = [CLBNode(node_id="node1", address="ip1", description=CLBDescription(lb_id="lb1", port=80))]
        rcv3_nodes = [RCv3Node(node_id="node2", cloud_server_id="a", description=RCv3Description(lb_id="lb2"))]

        eff = get_all_convergence_data(
            "tid",
            "gid",
            self.now,
            get_scaling_group_servers=_constant_as_eff(("tid", "gid", self.now), self.servers),
            get_clb_contents=_constant_as_eff((), clb_nodes),
            get_rcv3_contents=_constant_as_eff((), rcv3_nodes),
        )

        expected_servers = [
            server(
                "a",
                ServerState.ACTIVE,
                servicenet_address="10.0.0.1",
                links=freeze([{"href": "link1", "rel": "self"}]),
                json=freeze(self.servers[0]),
            ),
            server(
                "b",
                ServerState.ACTIVE,
                created=1,
                servicenet_address="10.0.0.2",
                links=freeze([{"href": "link2", "rel": "self"}]),
                json=freeze(self.servers[1]),
            ),
        ]
        self.assertEqual(resolve_stubs(eff), (expected_servers, clb_nodes + rcv3_nodes))
Example #8
0
 def test_add_effect_on_response(self):
     """Test the decorator :func:`add_effect_on_response`."""
     badauth = stub_pure_response("badauth!", code=401)
     request_ = add_effect_on_response(self.invalidate_effect, (401, ),
                                       stub_request(badauth))
     eff = request_('m', 'u')
     self.assertEqual(resolve_stubs(eff), badauth)
     self.assertEqual(self.invalidations, [True])
Example #9
0
 def test_add_effect_on_response(self):
     """Test the decorator :func:`add_effect_on_response`."""
     badauth = stub_pure_response("badauth!", code=401)
     request_ = add_effect_on_response(
         self.invalidate_effect, (401,), stub_request(badauth))
     eff = request_('m', 'u')
     self.assertEqual(resolve_stubs(eff), badauth)
     self.assertEqual(self.invalidations, [True])
Example #10
0
 def test_add_headers(self):
     """Headers are merged, with passed headers taking precedence."""
     request_ = add_headers({'one': '1', 'two': '2'}, request)
     eff = request_('m', 'u', headers={'one': 'hey', 'three': '3'})
     self.assertEqual(
         resolve_stubs(eff).intent,
         Request(method='m',
                 url='u',
                 headers={'one': 'hey', 'two': '2', 'three': '3'}))
Example #11
0
 def test_empty_json_response(self):
     """
     If the body is empty, it will be turned into :data:`None`, and not
     passed to the JSON parser.
     """
     response = stub_pure_response('', 204)
     request_ = add_json_response(stub_request(response))
     self.assertEqual(resolve_stubs(request_('m', 'u')),
                      (response[0], None))
Example #12
0
 def test_add_headers_optional(self):
     """It's okay if no headers are passed."""
     request_ = add_effectful_headers(self.auth_effect, request)
     eff = request_('m', 'u')
     self.assertEqual(
         resolve_stubs(eff).intent,
         Request(method='m',
                 url='u',
                 headers={'x-auth-token': 'abc123'}))
Example #13
0
 def test_added_headers_win(self):
     """When merging headers together, headers from the effect win."""
     request_ = add_effectful_headers(self.auth_effect, request)
     eff = request_('m', 'u', headers={'x-auth-token': 'fooey'})
     self.assertEqual(
         resolve_stubs(eff).intent,
         Request(method="m",
                 url="u",
                 headers={"x-auth-token": "abc123"}))
Example #14
0
 def test_empty_json_response(self):
     """
     If the body is empty, it will be turned into :data:`None`, and not
     passed to the JSON parser.
     """
     response = stub_pure_response('', 204)
     request_ = add_json_response(stub_request(response))
     self.assertEqual(resolve_stubs(request_('m', 'u')),
                      (response[0], None))
Example #15
0
 def test_add_headers_optional(self):
     """It's okay if no headers are passed."""
     request_ = add_headers({'one': '1'}, request)
     eff = request_('m', 'u')
     self.assertEqual(
         resolve_stubs(eff).intent,
         Request(method='m',
                 url='u',
                 headers={'one': '1'}))
Example #16
0
 def test_add_headers(self):
     """Headers from the provided effect are inserted."""
     request_ = add_effectful_headers(self.auth_effect, request)
     eff = request_('m', 'u', headers={'default': 'headers'})
     self.assertEqual(
         resolve_stubs(eff).intent,
         Request(method="m",
                 url="u",
                 headers={"x-auth-token": "abc123",
                          "default": "headers"}))
Example #17
0
 def test_invalidate(self):
     """
     :func:`effect_on_response` invokes the provided effect and
     returns an Effect of the original response.
     """
     badauth = stub_pure_response("badauth!", code=401)
     eff = effect_on_response((401,), self.invalidate_effect, badauth)
     self.assertEqual(eff.intent, self.invalidate_effect.intent)
     self.assertEqual(resolve_stubs(eff), badauth)
     self.assertEqual(self.invalidations, [True])
Example #18
0
 def test_invalidate(self):
     """
     :func:`effect_on_response` invokes the provided effect and
     returns an Effect of the original response.
     """
     badauth = stub_pure_response("badauth!", code=401)
     eff = effect_on_response((401, ), self.invalidate_effect, badauth)
     self.assertEqual(eff.intent, self.invalidate_effect.intent)
     self.assertEqual(resolve_stubs(eff), badauth)
     self.assertEqual(self.invalidations, [True])
Example #19
0
 def test_add_headers(self):
     """Headers from the provided effect are inserted."""
     request_ = add_effectful_headers(self.auth_effect, request)
     eff = request_('m', 'u', headers={'default': 'headers'})
     self.assertEqual(
         resolve_stubs(eff).intent,
         Request(method="m",
                 url="u",
                 headers={
                     "x-auth-token": "abc123",
                     "default": "headers"
                 }))
Example #20
0
    def test_no_group_stacks(self):
        """
        If there are no stacks in a group, get_all_launch_stack_data returns
        an empty list.
        """
        eff = get_all_launch_stack_data(
            'tid',
            'gid',
            self.now,
            get_scaling_group_stacks=_constant_as_eff(('gid',), []))

        self.assertEqual(resolve_stubs(eff), {'stacks': []})
Example #21
0
    def test_no_group_stacks(self):
        """
        If there are no stacks in a group, get_all_launch_stack_data returns
        an empty list.
        """
        eff = get_all_launch_stack_data(
            'tid',
            'gid',
            self.now,
            get_scaling_group_stacks=_constant_as_eff(('gid',), []))

        self.assertEqual(resolve_stubs(eff), {'stacks': []})
Example #22
0
 def test_add_headers(self):
     """Headers are merged, with passed headers taking precedence."""
     request_ = add_headers({'one': '1', 'two': '2'}, request)
     eff = request_('m', 'u', headers={'one': 'hey', 'three': '3'})
     self.assertEqual(
         resolve_stubs(eff).intent,
         Request(method='m',
                 url='u',
                 headers={
                     'one': 'hey',
                     'two': '2',
                     'three': '3'
                 }))
Example #23
0
    def test_success(self):
        """HeatStack instances should be returned from JSON."""
        expected_stacks = [
            stack(id='a', name='aa', action='CREATE', status='COMPLETE'),
            stack(id='b', name='bb', action='CREATE', status='COMPLETE')
        ]
        eff = get_all_launch_stack_data(
            'tid',
            'gid',
            self.now,
            get_scaling_group_stacks=_constant_as_eff(('gid',), self.stacks))

        self.assertEqual(resolve_stubs(eff), {'stacks': expected_stacks})
Example #24
0
    def test_success(self):
        """HeatStack instances should be returned from JSON."""
        expected_stacks = [
            stack(id='a', name='aa', action='CREATE', status='COMPLETE'),
            stack(id='b', name='bb', action='CREATE', status='COMPLETE')
        ]
        eff = get_all_launch_stack_data(
            'tid',
            'gid',
            self.now,
            get_scaling_group_stacks=_constant_as_eff(('gid',), self.stacks))

        self.assertEqual(resolve_stubs(eff), {'stacks': expected_stacks})
Example #25
0
    def test_no_group_servers(self):
        """
        If there are no servers in a group, get_all_launch_server_data includes
        an empty list.
        """
        eff = get_all_launch_server_data(
            'tid',
            'gid',
            self.now,
            get_scaling_group_servers=_constant_as_eff(
                ('tid', 'gid', self.now), []),
            get_clb_contents=_constant_as_eff((), []),
            get_rcv3_contents=_constant_as_eff((), []))

        self.assertEqual(resolve_stubs(eff), {'servers': [], 'lb_nodes': []})
Example #26
0
    def test_no_group_servers(self):
        """
        If there are no servers in a group, get_all_launch_server_data includes
        an empty list.
        """
        eff = get_all_launch_server_data(
            'tid',
            'gid',
            self.now,
            get_scaling_group_servers=_constant_as_eff(
                ('tid', 'gid', self.now), []),
            get_clb_contents=_constant_as_eff((), []),
            get_rcv3_contents=_constant_as_eff((), []))

        self.assertEqual(resolve_stubs(eff), {'servers': [], 'lb_nodes': []})
Example #27
0
    def test_no_group_servers(self):
        """
        If there are no servers in a group, get_all_convergence_data includes
        an empty list.
        """
        eff = get_all_convergence_data(
            "tid",
            "gid",
            self.now,
            get_scaling_group_servers=_constant_as_eff(("tid", "gid", self.now), []),
            get_clb_contents=_constant_as_eff((), []),
            get_rcv3_contents=_constant_as_eff((), []),
        )

        self.assertEqual(resolve_stubs(eff), ([], []))
Example #28
0
 def test_add_content_only(self):
     """The produced request function results in the content."""
     request_ = add_content_only(
         stub_request(stub_pure_response('foo', 200)))
     eff = request_('m', 'u')
     self.assertEqual(resolve_stubs(eff), 'foo')
Example #29
0
 def test_add_json_response(self):
     """The produced request function results in a parsed data structure."""
     response = stub_pure_response('{"a": "b"}', 200)
     request_ = add_json_response(stub_request(response))
     self.assertEqual(resolve_stubs(request_('m', 'u')),
                      (response[0], {'a': 'b'}))
Example #30
0
 def test_add_content_only(self):
     """The produced request function results in the content."""
     request_ = add_content_only(stub_request(stub_pure_response('foo', 200)))
     eff = request_('m', 'u')
     self.assertEqual(resolve_stubs(eff), 'foo')