Example #1
0
 def test_option_not_present(self):
     """Names of options not included are returned."""
     # no mirror-gpg-key
     config = {
         'mirrors': 'some mirrors',
         'sign-gpg-key': 'mykey',
     }
     self.assertEqual(missing_options(config), ['repository-origin'])
Example #2
0
 def test_all_options(self):
     """If all required options are set, an empty list is returned."""
     config = {
         'mirrors': 'some mirrors',
         'repository-origin': 'Ubuntu',
         'sign-gpg-key': 'mykey',
     }
     self.assertEqual(missing_options(config), [])
Example #3
0
 def test_option_empty_string(self):
     """Names of empty options are returned."""
     # no mirror-gpg-key
     config = {
         'mirrors': 'some mirrors',
         'repository-origin': 'Ubuntu',
         'sign-gpg-key': '',
     }
     self.assertEqual(missing_options(config), ['sign-gpg-key'])
Example #4
0
 def test_option_none(self):
     """Names of None options are returned."""
     # no mirror-gpg-key
     config = {
         'mirrors': None,
         'repository-origin': 'Ubuntu',
         'sign-gpg-key': None,
     }
     missing = sorted(missing_options(config))
     self.assertEqual(list(missing), ['mirrors', 'sign-gpg-key'])
Example #5
0
def config_set():
    config = hookenv.config()
    missing_options = setup.missing_options(config)
    if missing_options:
        hookenv.status_set(
            'blocked',
            'Mirroring is disabled as some configuration options are missing: '
            '{}'.format(', '.join(missing_options)))
        return

    # Configure mirroring.
    keyring = gpg.KeyRing()
    mirrors = mirror.from_config(keyring, config['mirrors'],
                                 config['repository-origin'].strip())
    sign_key_fingerprint = keyring.import_key(config['sign-gpg-key'])
    sign_key_passphrase = config.get('sign-gpg-passphrase', '').strip()
    repository.configure_reprepro(mirrors, sign_key_fingerprint,
                                  sign_key_passphrase)
    # Export the public key used to sign the repository.
    _export_sign_key(sign_key_fingerprint)
    hookenv.status_set('active', 'Mirroring configured')