Exemplo n.º 1
0
 def test_without_image_id(self):
     """
     Create server that has missing image in it in various ways.
     (for the case of BFV)
     """
     for image in ({}, {'id': None}, ""):
         self.servers[0]['image'] = image
         self.assertEqual(
             NovaServer.from_server_details_json(self.servers[0]),
             NovaServer(id='a',
                        state=ServerState.ACTIVE,
                        image_id=None,
                        flavor_id='valid_flavor',
                        created=self.createds[0],
                        servicenet_address='',
                        links=freeze(self.servers[0]['links']),
                        json=freeze(self.servers[0])))
     del self.servers[0]['image']
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[0]),
         NovaServer(id='a',
                    state=ServerState.ACTIVE,
                    image_id=None,
                    flavor_id='valid_flavor',
                    created=self.createds[0],
                    servicenet_address='',
                    links=freeze(self.servers[0]['links']),
                    json=freeze(self.servers[0])))
Exemplo n.º 2
0
 def test_without_image_id(self):
     """
     Create server that has missing image in it in various ways.
     (for the case of BFV)
     """
     for image in ({}, {'id': None}, ""):
         self.servers[0]['image'] = image
         self.assertEqual(
             NovaServer.from_server_details_json(self.servers[0]),
             NovaServer(id='a',
                        state=ServerState.ACTIVE,
                        image_id=None,
                        flavor_id='valid_flavor',
                        created=self.createds[0],
                        servicenet_address='',
                        links=freeze(self.servers[0]['links']),
                        json=freeze(self.servers[0])))
     del self.servers[0]['image']
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[0]),
         NovaServer(id='a',
                    state=ServerState.ACTIVE,
                    image_id=None,
                    flavor_id='valid_flavor',
                    created=self.createds[0],
                    servicenet_address='',
                    links=freeze(self.servers[0]['links']),
                    json=freeze(self.servers[0])))
Exemplo n.º 3
0
 def test_without_image_id(self):
     """
     Create server that has missing image in it in various ways.
     (for the case of BFV)
     """
     for image in ({}, {"id": None}):
         self.servers[0]["image"] = image
         self.assertEqual(
             NovaServer.from_server_details_json(self.servers[0]),
             NovaServer(
                 id="a",
                 state=ServerState.ACTIVE,
                 image_id=None,
                 flavor_id="valid_flavor",
                 created=self.createds[0][1],
                 servicenet_address="",
                 links=freeze(self.links[0]),
                 json=freeze(self.servers[0]),
             ),
         )
     del self.servers[0]["image"]
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[0]),
         NovaServer(
             id="a",
             state=ServerState.ACTIVE,
             image_id=None,
             flavor_id="valid_flavor",
             created=self.createds[0][1],
             servicenet_address="",
             links=freeze(self.links[0]),
             json=freeze(self.servers[0]),
         ),
     )
Exemplo n.º 4
0
 def test_without_address(self):
     """
     Handles server json that does not have "addresses" in it.
     """
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[0]),
         NovaServer(id='a',
                    state=ServerState.ACTIVE,
                    image_id='valid_image',
                    flavor_id='valid_flavor',
                    created=self.createds[0],
                    servicenet_address='',
                    links=freeze(self.servers[0]['links']),
                    json=freeze(self.servers[0])))
Exemplo n.º 5
0
 def test_with_servicenet(self):
     """
     Create server that has servicenet IP in it.
     """
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[1]),
         NovaServer(id='b',
                    state=ServerState.BUILD,
                    image_id='valid_image',
                    flavor_id='valid_flavor',
                    created=self.createds[1],
                    servicenet_address='10.0.0.1',
                    links=freeze(self.servers[1]['links']),
                    json=freeze(self.servers[1])))
Exemplo n.º 6
0
 def test_without_private(self):
     """
     Creates server that does not have private/servicenet IP in it.
     """
     self.servers[0]['addresses'] = {'public': 'p'}
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[0]),
         NovaServer(id='a',
                    state=ServerState.ACTIVE,
                    image_id='valid_image',
                    flavor_id='valid_flavor',
                    created=self.createds[0],
                    servicenet_address='',
                    links=freeze(self.servers[0]['links']),
                    json=freeze(self.servers[0])))
Exemplo n.º 7
0
 def test_matches_only_if_server_address_matches_node_address(self):
     """
     :func:`CLBNode.matches` returns True only if the :class:`NovaServer`
     has the same ServiceNet address as the node address
     """
     node = CLBNode(node_id='1234', description=self.desc,
                    address='10.1.1.1')
     self.assertFalse(node.matches(
         NovaServer(id='1', state=ServerState.ACTIVE, created=0.0,
                    servicenet_address="10.1.1.2",
                    image_id='image', flavor_id='flavor')))
     self.assertTrue(node.matches(
         NovaServer(id='1', state=ServerState.ACTIVE, created=0.0,
                    servicenet_address="10.1.1.1",
                    image_id='image', flavor_id='flavor')))
Exemplo n.º 8
0
 def test_repr_nova(self):
     """
     The repr of a Nova server includes thawed data structures and shortened
     JSON.
     """
     server_json = self.servers[0]
     # add a bunch more fields
     server_json.update({
         'metadata': {'some': 'stuff'},
         'OS-EXT-STS:task_state': None,
         'updated': '2020-10-10T10:00:00Z',
         'user': '******',
         'hostId': '12356773526246'
     })
     server = NovaServer.from_server_details_json(server_json)
     expected_json = {
         'status': server_json['status'],
         'OS-EXT-STS:task_state': None,
         'updated': '2020-10-10T10:00:00Z',
         'metadata': {'some': 'stuff'}
     }
     self.assertEqual(
         repr(server),
         "<NovaServer(id={0}, state={1}, created={2}, image_id={3}, "
         "flavor_id={4}, links={5}, desired_lbs={6}, "
         "servicenet_address={7}, json={8})>".format(*[repr(i) for i in [
             'a', ServerState.ACTIVE, float(self.createds[0]),
             'valid_image', 'valid_flavor', self.servers[0]['links'], set(),
             '', expected_json]]))
Exemplo n.º 9
0
 def test_repr_nova(self):
     """
     The repr of a Nova server includes thawed data structures and shortened
     JSON.
     """
     server_json = self.servers[0]
     # add a bunch more fields
     server_json.update({
         'metadata': {'some': 'stuff'},
         'OS-EXT-STS:task_state': None,
         'updated': '2020-10-10T10:00:00Z',
         'user': '******',
         'hostId': '12356773526246'
     })
     server = NovaServer.from_server_details_json(server_json)
     expected_json = {
         'status': server_json['status'],
         'OS-EXT-STS:task_state': None,
         'updated': '2020-10-10T10:00:00Z',
         'metadata': {'some': 'stuff'}
     }
     self.assertEqual(
         repr(server),
         "<NovaServer(id={0}, state={1}, created={2}, image_id={3}, "
         "flavor_id={4}, links={5}, desired_lbs={6}, "
         "servicenet_address={7}, json={8})>".format(*[repr(i) for i in [
             'a', ServerState.ACTIVE, float(self.createds[0]),
             'valid_image', 'valid_flavor', self.servers[0]['links'], set(),
             '', expected_json]]))
Exemplo n.º 10
0
 def test_deleting_server(self):
     """
     A server whose "OS-EXT-STS:task_state" is "deleting" will be considered
     as DELETED
     """
     self.servers[0]["OS-EXT-STS:task_state"] = "deleting"
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[0]),
         NovaServer(id='a',
                    state=ServerState.DELETED,
                    image_id='valid_image',
                    flavor_id='valid_flavor',
                    created=self.createds[0],
                    desired_lbs=pset(),
                    servicenet_address='',
                    links=freeze(self.servers[0]['links']),
                    json=freeze(self.servers[0])))
Exemplo n.º 11
0
 def _create_servers(self, n, state=ServerState.ACTIVE):
     """
     Create some dummy test servers.
     """
     return pset([
         NovaServer(id=str(i), state=state, created=123456789.,
                    image_id='image', flavor_id='flavor')
         for i in xrange(n)
     ])
Exemplo n.º 12
0
 def test_unknown_state(self):
     """
     When nova provides an unknown server state, it's set to
     ``ServerState.UNKNOWN_TO_OTTER`` on the :obj:`NovaServer`.
     """
     server_json = self.servers[0].copy()
     # add a bunch more fields
     server_json['status'] = 'ablrduelh'
     server = NovaServer.from_server_details_json(server_json)
     self.assertEqual(server.state, ServerState.UNKNOWN_TO_OTTER)
     self.assertEqual(server.json['status'], 'ablrduelh')
Exemplo n.º 13
0
 def test_unknown_state(self):
     """
     When nova provides an unknown server state, it's set to
     ``ServerState.UNKNOWN_TO_OTTER`` on the :obj:`NovaServer`.
     """
     server_json = self.servers[0].copy()
     # add a bunch more fields
     server_json['status'] = 'ablrduelh'
     server = NovaServer.from_server_details_json(server_json)
     self.assertEqual(server.state, ServerState.UNKNOWN_TO_OTTER)
     self.assertEqual(server.json['status'], 'ablrduelh')
Exemplo n.º 14
0
 def test_lbs_from_metadata_ignores_unsupported_lb_types(self):
     """
     Creating from server json ignores unsupported LB types
     """
     self.servers[0]['metadata'] = {
         "rax:autoscale:lb:1": '[{"port":80},{"port":90}]',
         "rax:autoscale:lb:RackConnect:{0}".format(uuid4()): None,
         "rax:autoscale:lb:Neutron:456": None
     }
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[0]),
         NovaServer(id='a',
                    state=ServerState.ACTIVE,
                    image_id='valid_image',
                    flavor_id='valid_flavor',
                    created=self.createds[0],
                    desired_lbs=pset(),
                    servicenet_address='',
                    links=freeze(self.servers[0]['links']),
                    json=freeze(self.servers[0])))
Exemplo n.º 15
0
 def test_without_address(self):
     """
     Handles server json that does not have "addresses" in it.
     """
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[0]),
         NovaServer(id='a',
                    state=ServerState.ACTIVE,
                    image_id='valid_image',
                    flavor_id='valid_flavor',
                    created=self.createds[0],
                    servicenet_address='',
                    links=freeze(self.servers[0]['links']),
                    json=freeze(self.servers[0])))
Exemplo n.º 16
0
def server(id, state, created=0, image_id='image', flavor_id='flavor',
           json=None, metadata=pmap(), **kwargs):
    """Convenience for creating a :obj:`NovaServer`."""
    json = pmap(json) or pmap({'id': id, 'status': state.name})
    if state is ServerState.UNKNOWN_TO_OTTER:
        json = json.set('status', 'blargho')
    elif state is ServerState.DELETED:
        json = json.set('status', 'ACTIVE')
        json = json.set('OS-EXT-STS:task_state', 'deleting')
    if metadata:
        json = json.set('metadata', pmap(metadata))
    return NovaServer(id=id, state=state, created=created, image_id=image_id,
                      flavor_id=flavor_id,
                      json=json, **kwargs)
Exemplo n.º 17
0
 def test_with_servicenet(self):
     """
     Create server that has servicenet IP in it.
     """
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[1]),
         NovaServer(id='b',
                    state=ServerState.BUILD,
                    image_id='valid_image',
                    flavor_id='valid_flavor',
                    created=self.createds[1],
                    servicenet_address='10.0.0.1',
                    links=freeze(self.servers[1]['links']),
                    json=freeze(self.servers[1])))
Exemplo n.º 18
0
    def test_with_lb_metadata(self):
        """
        Create a server that has load balancer config metadata in it.
        The only desired load balancers created are the ones with valid
        data.
        """
        self.servers[0]['metadata'] = {
            # correct clb config
            'rax:autoscale:lb:CloudLoadBalancer:1':
            '[{"port":80},{"port":90}]',

            # invalid because there is no port
            "rax:autoscale:lb:CloudLoadBalancer:2": '[{}]',
            # two correct lbconfigs and one incorrect one
            'rax:autoscale:lb:CloudLoadBalancer:3':
            '[{"port":80},{"bad":"1"},{"port":90}]',
            # a dictionary instead of a list
            'rax:autoscale:lb:CloudLoadBalancer:4': '{"port": 80}',
            # not even valid json
            'rax:autoscale:lb:CloudLoadBalancer:5': 'invalid json string',
            # RCv3 with same LB id as CLB
            'rax:autoscale:lb:RackConnectV3:1': ''
        }
        self.assertEqual(
            NovaServer.from_server_details_json(self.servers[0]),
            NovaServer(id='a',
                       state=ServerState.ACTIVE,
                       image_id='valid_image',
                       flavor_id='valid_flavor',
                       created=self.createds[0],
                       desired_lbs=pset([
                           CLBDescription(lb_id='1', port=80),
                           CLBDescription(lb_id='1', port=90),
                           RCv3Description(lb_id='1')]),
                       servicenet_address='',
                       links=freeze(self.servers[0]['links']),
                       json=freeze(self.servers[0])))
Exemplo n.º 19
0
 def test_without_private(self):
     """
     Creates server that does not have private/servicenet IP in it.
     """
     self.servers[0]['addresses'] = {'public': 'p'}
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[0]),
         NovaServer(id='a',
                    state=ServerState.ACTIVE,
                    image_id='valid_image',
                    flavor_id='valid_flavor',
                    created=self.createds[0],
                    servicenet_address='',
                    links=freeze(self.servers[0]['links']),
                    json=freeze(self.servers[0])))
Exemplo n.º 20
0
 def test_with_servicenet(self):
     """
     Create server that has servicenet IP in it.
     """
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[1]),
         NovaServer(
             id="b",
             state=ServerState.BUILD,
             image_id="valid_image",
             flavor_id="valid_flavor",
             created=self.createds[1][1],
             servicenet_address="10.0.0.1",
             links=freeze(self.links[1]),
             json=freeze(self.servers[1]),
         ),
     )
Exemplo n.º 21
0
 def test_deleting_server(self):
     """
     A server whose "OS-EXT-STS:task_state" is "deleting" will be considered
     as DELETED
     """
     self.servers[0]["OS-EXT-STS:task_state"] = "deleting"
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[0]),
         NovaServer(id='a',
                    state=ServerState.DELETED,
                    image_id='valid_image',
                    flavor_id='valid_flavor',
                    created=self.createds[0],
                    desired_lbs=pset(),
                    servicenet_address='',
                    links=freeze(self.servers[0]['links']),
                    json=freeze(self.servers[0])))
Exemplo n.º 22
0
 def test_without_private(self):
     """
     Creates server that does not have private/servicenet IP in it.
     """
     self.servers[0]["addresses"] = {"public": "p"}
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[0]),
         NovaServer(
             id="a",
             state=ServerState.ACTIVE,
             image_id="valid_image",
             flavor_id="valid_flavor",
             created=self.createds[0][1],
             servicenet_address="",
             links=freeze(self.links[0]),
             json=freeze(self.servers[0]),
         ),
     )
Exemplo n.º 23
0
 def test_repr_nova(self):
     """
     The repr of a Nova server includes thawed data structures and shortened
     JSON.
     """
     server_json = self.servers[0]
     # add a bunch more fields
     server_json.update(
         {
             "metadata": {"some": "stuff"},
             "OS-EXT-STS:task_state": None,
             "updated": self.createds[0][0],
             "user": "******",
             "hostId": "12356773526246",
         }
     )
     server = NovaServer.from_server_details_json(server_json)
     expected_json = {
         "status": server_json["status"],
         "OS-EXT-STS:task_state": None,
         "updated": self.createds[0][0],
         "metadata": {"some": "stuff"},
     }
     self.assertEqual(
         repr(server),
         "<NovaServer(id={0}, state={1}, created={2}, image_id={3}, "
         "flavor_id={4}, links={5}, desired_lbs={6}, "
         "servicenet_address={7}, json={8})>".format(
             *[
                 repr(i)
                 for i in [
                     "a",
                     ServerState.ACTIVE,
                     float(self.createds[0][1]),
                     "valid_image",
                     "valid_flavor",
                     self.links[0],
                     set(),
                     "",
                     expected_json,
                 ]
             ]
         ),
     )
Exemplo n.º 24
0
 def test_lbs_from_metadata_ignores_unsupported_lb_types(self):
     """
     Creating from server json ignores unsupported LB types
     """
     self.servers[0]['metadata'] = {
         "rax:autoscale:lb:1": '[{"port":80},{"port":90}]',
         "rax:autoscale:lb:RackConnect:{0}".format(uuid4()): None,
         "rax:autoscale:lb:Neutron:456": None
     }
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[0]),
         NovaServer(id='a',
                    state=ServerState.ACTIVE,
                    image_id='valid_image',
                    flavor_id='valid_flavor',
                    created=self.createds[0],
                    desired_lbs=pset(),
                    servicenet_address='',
                    links=freeze(self.servers[0]['links']),
                    json=freeze(self.servers[0])))
Exemplo n.º 25
0
    def test_with_lb_metadata(self):
        """
        Create a server that has load balancer config metadata in it.
        The only desired load balancers created are the ones with valid
        data.
        """
        self.servers[0]['metadata'] = {
            # correct clb config
            'rax:autoscale:lb:CloudLoadBalancer:1':
            '[{"port":80},{"port":90}]',

            # invalid because there is no port
            "rax:autoscale:lb:CloudLoadBalancer:2": '[{}]',
            # two correct lbconfigs and one incorrect one
            'rax:autoscale:lb:CloudLoadBalancer:3':
            '[{"port":80},{"bad":"1"},{"port":90}]',
            # a dictionary instead of a list
            'rax:autoscale:lb:CloudLoadBalancer:4': '{"port": 80}',
            # not even valid json
            'rax:autoscale:lb:CloudLoadBalancer:5': 'invalid json string',
            # RCv3 with same LB id as CLB
            'rax:autoscale:lb:RackConnectV3:1': ''
        }
        self.assertEqual(
            NovaServer.from_server_details_json(self.servers[0]),
            NovaServer(id='a',
                       state=ServerState.ACTIVE,
                       image_id='valid_image',
                       flavor_id='valid_flavor',
                       created=self.createds[0],
                       desired_lbs=pset([
                           CLBDescription(lb_id='1', port=80),
                           CLBDescription(lb_id='1', port=90),
                           RCv3Description(lb_id='1')]),
                       servicenet_address='',
                       links=freeze(self.servers[0]['links']),
                       json=freeze(self.servers[0])))
Exemplo n.º 26
0
 def test_with_lb_metadata(self):
     """
     Create a server that has load balancer config metadata in it.
     The only desired load balancers created are the ones with valid
     data.
     """
     self.servers[0]["metadata"] = {
         # correct clb config
         "rax:autoscale:lb:CloudLoadBalancer:1": '[{"port":80},{"port":90}]',
         # invalid because there is no port
         "rax:autoscale:lb:CloudLoadBalancer:2": "[{}]",
         # two correct lbconfigs and one incorrect one
         "rax:autoscale:lb:CloudLoadBalancer:3": '[{"port":80},{"bad":"1"},{"port":90}]',
         # a dictionary instead of a list
         "rax:autoscale:lb:CloudLoadBalancer:4": '{"port": 80}',
         # not even valid json
         "rax:autoscale:lb:CloudLoadBalancer:5": "invalid json string",
         # RCv3 with same LB id as CLB
         "rax:autoscale:lb:RackConnectV3:1": "",
     }
     self.assertEqual(
         NovaServer.from_server_details_json(self.servers[0]),
         NovaServer(
             id="a",
             state=ServerState.ACTIVE,
             image_id="valid_image",
             flavor_id="valid_flavor",
             created=self.createds[0][1],
             desired_lbs=pset(
                 [CLBDescription(lb_id="1", port=80), CLBDescription(lb_id="1", port=90), RCv3Description(lb_id="1")]
             ),
             servicenet_address="",
             links=freeze(self.links[0]),
             json=freeze(self.servers[0]),
         ),
     )