Exemplo n.º 1
0
 def test_load_proof_extensions(self):
     mocks = {
         'validate_storage': None,
         'validate_devices': None,
         'validate_resources': None,
         'validate_payloads': None,
     }
     for validator in mocks.keys():
         patcher = patch('charmtools.charms.{}'.format(validator))
         mocks[validator] = patcher.start()
         self.addCleanup(patcher.stop)
     self.write_metadata("{}")
     with open(join(self.charm_dir, 'layer.yaml'), 'w') as f:
         f.write(dedent("""
                        proof:
                          storage:
                            - name: ext
                              type: Boolean
                          devices:
                            - name: ext
                              type: Boolean
                          resources:
                            - name: ext
                              type: Boolean
                          payloads:
                            - name: ext
                              type: Boolean
                        """))
     charm = Charm(self.charm_dir, self.linter)
     charm.proof()
     for mock in mocks.values():
         mock.assert_called_once_with({},
                                      self.linter,
                                      [{'name': 'ext',
                                        'type': 'Boolean'}])
Exemplo n.º 2
0
 def test_valid_layer_yaml(self):
     self.write_metadata("{}")
     with open(join(self.charm_dir, 'layer.yaml'), 'w') as f:
         f.write("valid: {}")
     with patch.object(Charm, 'is_charm'):
         charm = Charm(self.charm_dir, self.linter)
     charm.proof()
     assert not any(msg.startswith('W: cannot parse {}/layer.yaml: '
                                   ''.format(self.charm_dir))
                    for msg in self.linter.lint)
Exemplo n.º 3
0
 def test_valid_layer_yaml(self):
     with open(join(self.charm_dir, 'metadata.yaml'), 'w') as f:
         f.write("{}")
     with open(join(self.charm_dir, 'layer.yaml'), 'w') as f:
         f.write("valid: {}")
     with patch.object(Charm, 'is_charm'):
         charm = Charm(self.charm_dir, self.linter)
     charm.proof()
     assert not any(msg.startswith('W: cannot parse {}/layer.yaml: '
                                   ''.format(self.charm_dir))
                    for msg in self.linter.lint)
Exemplo n.º 4
0
def proof(path, is_bundle, debug):
    messages = []
    exit_code = 0
    path = os.path.abspath(path)
    home_path = utils.get_home()
    home_msg = ('For security reasons, only paths under '
                'your home directory can be accessed')
    if not home_path:  # expansion failed
        messages.append('Could not determine home directory')
        messages.append(home_msg)
    elif not path.startswith(home_path):
        messages.append('The path {} is not under your '
                        'home directory'.format(path))
        messages.append(home_msg)
    if not os.access(path, os.R_OK):
        messages.append('Unable to read from {}'.format(path))
        exit_code = 200
        return messages, exit_code
    if not is_bundle:
        try:
            c = Charm(path)
        except:
            try:
                c = Bundle(path, debug)
            except Exception as e:
                return ["FATAL: No bundle.yaml (Bundle) or metadata.yaml "
                        "(Charm) found, cannot proof"], 200
    else:
        try:
            c = Bundle(path, debug)
        except Exception as e:
            return ["FATAL: %s" % e.message], 200

    lint, err_code = c.proof()
    return lint, err_code
Exemplo n.º 5
0
def proof(path, is_bundle, debug):
    messages = []
    exit_code = 0
    path = os.path.abspath(path)
    if not os.access(path, os.R_OK):
        messages.append('Unable to read from {}'.format(path))
        exit_code = 200
        return messages, exit_code
    if not is_bundle:
        try:
            c = Charm(path)
        except Exception:
            try:
                c = Bundle(path, debug)
            except Exception as e:
                return [
                    "FATAL: No bundle.yaml (Bundle) or metadata.yaml "
                    "(Charm) found, cannot proof"
                ], 200
    else:
        try:
            c = Bundle(path, debug)
        except Exception as e:
            return ["FATAL: %s" % e.message], 200

    lint, err_code = c.proof()
    return lint, err_code
Exemplo n.º 6
0
 def test_load_proof_extensions(self):
     mocks = {
         'validate_storage': None,
         'validate_devices': None,
         'validate_resources': None,
         'validate_payloads': None,
     }
     for validator in mocks.keys():
         patcher = patch('charmtools.charms.{}'.format(validator))
         mocks[validator] = patcher.start()
         self.addCleanup(patcher.stop)
     with open(join(self.charm_dir, 'metadata.yaml'), 'w') as f:
         f.write("{}")
     with open(join(self.charm_dir, 'layer.yaml'), 'w') as f:
         f.write(dedent("""
                        proof:
                          storage:
                            - name: ext
                              type: Boolean
                          devices:
                            - name: ext
                              type: Boolean
                          resources:
                            - name: ext
                              type: Boolean
                          payloads:
                            - name: ext
                              type: Boolean
                        """))
     charm = Charm(self.charm_dir, self.linter)
     charm.proof()
     for mock in mocks.values():
         mock.assert_called_once_with({},
                                      self.linter,
                                      [{'name': 'ext',
                                        'type': 'Boolean'}])