예제 #1
0
 def test_creates_dictionary_of_arbitrary_depth(self):
     """
     :func:`get_service_metadata` creates a dictionary of arbitrary depth
     depending on how many colons are in the keys.
     """
     metadata = {
         "rax:autoscale:group:id": "group id",
         "rax:autoscale:lb:CloudLoadBalancer:123": "result1",
         "rax:autoscale:lb:CloudLoadBalancer:234": "result2",
         "rax:autoscale:lb:RackConnectV3:123": "result3",
         "rax:autoscale:lb:RackConnectV3:234": "result4",
         "rax:autoscale:some:other:nested:key": "result5",
         "rax:autoscale:topLevelKey_with_underlines-and-dashes": "result6",
         "rax:autoscale:autoscale:lb": "result7",
     }
     expected = {
         "group": {"id": "group id"},
         "lb": {
             "CloudLoadBalancer": {"123": "result1", "234": "result2"},
             "RackConnectV3": {"123": "result3", "234": "result4"},
         },
         "some": {"other": {"nested": {"key": "result5"}}},
         "topLevelKey_with_underlines-and-dashes": "result6",
         "autoscale": {"lb": "result7"},
     }
     self.assertEqual(get_service_metadata("autoscale", metadata), pmap(expected))
예제 #2
0
 def test_creates_dictionary_of_arbitrary_depth(self):
     """
     :func:`get_service_metadata` creates a dictionary of arbitrary depth
     depending on how many colons are in the keys.
     """
     metadata = {
         "rax:autoscale:group:id": "group id",
         "rax:autoscale:lb:CloudLoadBalancer:123": "result1",
         "rax:autoscale:lb:CloudLoadBalancer:234": "result2",
         "rax:autoscale:lb:RackConnectV3:123": "result3",
         "rax:autoscale:lb:RackConnectV3:234": "result4",
         "rax:autoscale:some:other:nested:key": "result5",
         "rax:autoscale:topLevelKey_with_underlines-and-dashes": "result6",
         "rax:autoscale:autoscale:lb": "result7"
     }
     expected = {
         'group': {'id': 'group id'},
         'lb': {
             'CloudLoadBalancer': {'123': 'result1',
                                   '234': 'result2'},
             'RackConnectV3': {'123': 'result3',
                               '234': 'result4'}
         },
         'some': {'other': {'nested': {'key': 'result5'}}},
         "topLevelKey_with_underlines-and-dashes": "result6",
         'autoscale': {'lb': 'result7'}
     }
     self.assertEqual(get_service_metadata('autoscale', metadata),
                      pmap(expected))
예제 #3
0
 def test_returns_empty_map_if_metadata_invalid(self):
     """
     If metadata is invalid (a string or otherwise not a dictionary),
     an empty map is returned.
     """
     for invalid in ("string", None, [], object()):
         self.assertEqual(get_service_metadata("autoscale", invalid), pmap())
예제 #4
0
 def test_creates_dictionary_of_arbitrary_depth(self):
     """
     :func:`get_service_metadata` creates a dictionary of arbitrary depth
     depending on how many colons are in the keys.
     """
     metadata = {
         "rax:autoscale:group:id": "group id",
         "rax:autoscale:lb:CloudLoadBalancer:123": "result1",
         "rax:autoscale:lb:CloudLoadBalancer:234": "result2",
         "rax:autoscale:lb:RackConnectV3:123": "result3",
         "rax:autoscale:lb:RackConnectV3:234": "result4",
         "rax:autoscale:some:other:nested:key": "result5",
         "rax:autoscale:topLevelKey_with_underlines-and-dashes": "result6",
         "rax:autoscale:autoscale:lb": "result7"
     }
     expected = {
         'group': {'id': 'group id'},
         'lb': {
             'CloudLoadBalancer': {'123': 'result1',
                                   '234': 'result2'},
             'RackConnectV3': {'123': 'result3',
                               '234': 'result4'}
         },
         'some': {'other': {'nested': {'key': 'result5'}}},
         "topLevelKey_with_underlines-and-dashes": "result6",
         'autoscale': {'lb': 'result7'}
     }
     self.assertEqual(get_service_metadata('autoscale', metadata),
                      pmap(expected))
예제 #5
0
 def test_returns_empty_map_if_metadata_invalid(self):
     """
     If metadata is invalid (a string or otherwise not a dictionary),
     an empty map is returned.
     """
     for invalid in ("string", None, [], object()):
         self.assertEqual(get_service_metadata('autoscale', invalid),
                          pmap())
예제 #6
0
 def test_skips_invalid_keys_and_mismatching_services(self):
     """
     :func:`get_service_metadata` ignores all keys that do not
     match the service or the `rax:<service>:...` naming scheme.
     """
     metadata = {
         "bleh:rax:autoscale:lb": "fails because starts with bleh",
         "rax:autoscale:lb otherstuff": "fails because space",
         "rax:monitoring:check": "fails because wrong service",
         ":rax:autoscale:lb": "fails because starts with colon",
         "rax:autoscale:lb:": "fails because ends with colon",
         "rax:rax:autoscale:lb:autoscale:lb": "fails because 2x'rax'"
     }
     self.assertEqual(get_service_metadata('autoscale', metadata), pmap())
예제 #7
0
 def test_skips_invalid_keys_and_mismatching_services(self):
     """
     :func:`get_service_metadata` ignores all keys that do not
     match the service or the `rax:<service>:...` naming scheme.
     """
     metadata = {
         "bleh:rax:autoscale:lb": "fails because starts with bleh",
         "rax:autoscale:lb otherstuff": "fails because space",
         "rax:monitoring:check": "fails because wrong service",
         ":rax:autoscale:lb": "fails because starts with colon",
         "rax:autoscale:lb:": "fails because ends with colon",
         "rax:rax:autoscale:lb:autoscale:lb": "fails because 2x'rax'"
     }
     self.assertEqual(get_service_metadata('autoscale', metadata), pmap())