Exemplo n.º 1
0
 def test_storage_invalid_values(self):
     """Charm has storage with invalid values."""
     linter = Mock()
     charm = {
         'storage': {
             'data': {
                 'type': 'unknown',
                 'shared': 'maybe',
                 'read-only': 'no',
                 'minimum-size': '10k',
             },
             'disks': {
                 'type': 'block',
                 'multiple': {
                     'range': '10+'
                 }
             }
         }
     }
     validate_storage(charm, linter)
     self.assertEqual(linter.err.call_count, 5)
     linter.err.assert_has_calls([
         call('storage.data.type: "unknown" is not one of '
              'filesystem, block'),
         call('storage.data.shared: "maybe" is not one of true, false'),
         call('storage.data.read-only: "no" is not one of true, false'),
         call('storage.data.minimum-size: must be a number followed by '
              'an optional M/G/T/P, e.g. 100M'),
         call('storage.disks.multiple.range: supported formats are: '
              'm (a fixed number), m-n (an explicit range), and '
              'm- (a minimum number)'),
     ], any_order=True)
Exemplo n.º 2
0
 def test_storage_invalid_values(self):
     """Charm has storage with invalid values."""
     linter = Mock()
     charm = {
         "storage": {
             "data": {"type": "unknown", "shared": "maybe", "read-only": "no", "minimum-size": "10k"},
             "disks": {"type": "block", "multiple": {"range": "10+"}},
         }
     }
     validate_storage(charm, linter)
     self.assertEqual(linter.err.call_count, 5)
     linter.err.assert_has_calls(
         [
             call('storage.data.type: "unknown" is not one of ' "filesystem, block"),
             call('storage.data.shared: "maybe" is not one of true, false'),
             call('storage.data.read-only: "no" is not one of true, false'),
             call("storage.data.minimum-size: must be a number followed by " "an optional M/G/T/P, e.g. 100M"),
             call(
                 "storage.disks.multiple.range: supported formats are: "
                 "m (a fixed number), m-n (an explicit range), and "
                 "m- (a minimum number)"
             ),
         ],
         any_order=True,
     )
Exemplo n.º 3
0
 def test_storage_without_defs(self):
     """Charm has storage key but no storage definitions."""
     linter = Mock()
     charm = {"storage": {}}
     validate_storage(charm, linter)
     self.assertEqual(linter.err.call_count, 1)
     linter.err.assert_has_calls([call("storage: must be a dictionary of storage definitions")], any_order=True)
Exemplo n.º 4
0
 def test_storage_unknown_keys(self):
     """Charm has storage with illegal keys."""
     linter = Mock()
     charm = {"storage": {"data": {"type": "filesystem", "unknown": "invalid key"}}}
     validate_storage(charm, linter)
     self.assertEqual(linter.err.call_count, 1)
     linter.err.assert_has_calls(
         [call("storage.data: Unrecognized keys in mapping: " "\"{'unknown': 'invalid key'}\"")], any_order=True
     )
Exemplo n.º 5
0
 def test_storage_without_defs(self):
     """Charm has storage key but no storage definitions."""
     linter = Mock()
     charm = {'storage': {}}
     validate_storage(charm, linter)
     self.assertEqual(linter.err.call_count, 1)
     linter.err.assert_has_calls([
         call('storage: must be a dictionary of storage definitions'),
     ],
                                 any_order=True)
Exemplo n.º 6
0
 def test_minimal_storage_config(self):
     """Charm has the minimum allowed storage configuration."""
     linter = Mock()
     charm = {
         'storage': {
             'data': {
                 'type': 'filesystem',
             }
         }
     }
     validate_storage(charm, linter)
     self.assertFalse(linter.err.called)
Exemplo n.º 7
0
 def test_storage_unknown_keys(self):
     """Charm has storage with illegal keys."""
     linter = Mock()
     charm = {
         'storage': {
             'data': {
                 'type': 'filesystem',
                 'unknown': 'invalid key',
             },
         }
     }
     validate_storage(charm, linter)
     self.assertEqual(linter.err.call_count, 1)
     linter.err.assert_has_calls([
         call('storage.data: Unrecognized keys in mapping: '
              '"{\'unknown\': \'invalid key\'}"'),
     ], any_order=True)
Exemplo n.º 8
0
 def test_storage_proof_extensions(self):
     """Charm has storage with proof extensions."""
     linter = Mock()
     charm = {
         'storage': {
             'data': {
                 'type': 'filesystem',
                 'unknown': 'invalid key',
             },
         }
     }
     extensions = [{
         'name': 'unknown',
         'type': 'String',
     }]
     validate_storage(charm, linter, extensions)
     self.assertEqual(linter.err.call_args_list, [])
Exemplo n.º 9
0
 def test_complete_storage_config(self):
     """Charm has a storage configuration using all options."""
     linter = Mock()
     charm = {
         "storage": {
             "data": {
                 "type": "filesystem",
                 "description": "my storage",
                 "shared": False,
                 "read-only": "true",
                 "minimum-size": "10G",
                 "location": "/srv/data",
             },
             "disks": {"type": "block", "multiple": {"range": "10-"}},
         }
     }
     validate_storage(charm, linter)
     self.assertFalse(linter.err.called)
Exemplo n.º 10
0
 def test_storage_proof_extensions(self):
     """Charm has storage with proof extensions."""
     linter = Mock()
     charm = {
         'storage': {
             'data': {
                 'type': 'filesystem',
                 'unknown': 'invalid key',
             },
         }
     }
     extensions = [
         {
             'name': 'unknown',
             'type': 'String',
         }
     ]
     validate_storage(charm, linter, extensions)
     self.assertEqual(linter.err.call_args_list, [])
Exemplo n.º 11
0
 def test_complete_storage_config(self):
     """Charm has a storage configuration using all options."""
     linter = Mock()
     charm = {
         'storage': {
             'data': {
                 'type': 'filesystem',
                 'description': 'my storage',
                 'shared': False,
                 'read-only': 'true',
                 'minimum-size': '10G',
                 'location': '/srv/data',
             },
             'disks': {
                 'type': 'block',
                 'multiple': {
                     'range': '10-'
                 }
             }
         }
     }
     validate_storage(charm, linter)
     self.assertFalse(linter.err.called)
Exemplo n.º 12
0
 def test_minimal_storage_config(self):
     """Charm has the minimum allowed storage configuration."""
     linter = Mock()
     charm = {"storage": {"data": {"type": "filesystem"}}}
     validate_storage(charm, linter)
     self.assertFalse(linter.err.called)