Exemple #1
0
class BundleFragmentTestCase(unittest.TestCase):
    def setUp(self):
        self.tests_dir = Path(__file__).absolute().parent
        self.bundle_dir = self.tests_dir / 'bundle'
        self.bundle_yaml = (self.bundle_dir /
                            'openstack-base-bundle.yaml').read_text()
        self.bundle = Bundle(yaml.load(self.bundle_yaml))

    def test_bundle_load_fragment(self):
        "bundle.test_bundle_load_fragment"
        fragment = self.bundle._get_application_fragment('cinder')
        expected_keys = ['charm', 'num_units', 'options', 'to']
        assert set(fragment.to_dict().keys()) == set(expected_keys)
        assert fragment.name == 'cinder'

    def test_bundle_fragment_is_subordinate(self):
        "bundle.test_bundle_fragment_is_subordinate"
        fragment = self.bundle._get_application_fragment('ntp')
        assert fragment.is_subordinate
Exemple #2
0
    def test_bundle_subtract_fragment(self):
        "bundle.test_bundle_subtract_fragment"
        d = {
            'foo': {
                'bar': 1,
                'baz': 2,
            },
            'qux': [1, 2],
        }
        bundle = Bundle(d)
        bundle.subtract({'foo': None})
        # full key delete
        self.assertEqual(bundle, {'qux': [1, 2]})

        bundle = Bundle(d)
        bundle.subtract({'foo': {'baz': None}})

        # sub-key delete
        self.assertEqual(bundle, {'foo': {'bar': 1}, 'qux': [1, 2]})
Exemple #3
0
 def test_bundle_applications(self):
     "bundle.test_bundle_applications"
     bundle_yaml = (self.bundle_dir / 'ghost-bundle.yaml').read_text()
     bundle = Bundle(yaml.load(bundle_yaml))
     expected_apps = ['ghost', 'mysql', 'haproxy']
     assert set([x.name for x in bundle.applications]) == set(expected_apps)
Exemple #4
0
 def test_bundle_sanitized(self):
     "bundle.test_bundle_sanitized"
     bundle_yaml = (self.bundle_dir / 'ghost-bundle.yaml').read_text()
     bundle = Bundle(yaml.load(bundle_yaml))
     expected_keys = ['series', 'applications', 'relations']
     assert set(bundle.keys()) == set(expected_keys)
Exemple #5
0
 def setUp(self):
     self.tests_dir = Path(__file__).absolute().parent
     self.bundle_dir = self.tests_dir / 'bundle'
     self.bundle_yaml = (self.bundle_dir /
                         'openstack-base-bundle.yaml').read_text()
     self.bundle = Bundle(yaml.load(self.bundle_yaml))
Exemple #6
0
def setup_metadata_controller():
    """ Pulls in a local bundle or via charmstore api and sets up our
    controller. You can also further customize the bundle by providing a local
    bundle-custom.yaml that will be deep merged over whatever bundle is
    referenced. """
    spell_dir = Path(app.config['spell-dir'])
    bundle_filename = spell_dir / 'bundle.yaml'
    bundle_custom_filename = spell_dir / 'bundle-custom.yaml'
    if bundle_filename.exists():
        # Load bundle data early so we can merge any additional charm options
        bundle_data = Bundle(yaml.load(bundle_filename.read_text()))
    else:
        bundle_name = app.metadata.bundle_name
        if bundle_name is None:
            raise Exception(
                "Could not determine a bundle to download, please make sure "
                "the spell contains a 'bundle-name' field."
            )
        bundle_channel = app.conjurefile['channel']

        app.log.debug("Pulling bundle for {} from channel: {}".format(
            bundle_name, bundle_channel))
        bundle_data = Bundle(charm.get_bundle(bundle_name, bundle_channel))

    if bundle_custom_filename.exists():
        bundle_custom = yaml.load(slurp(bundle_custom_filename))
        bundle_data.apply(bundle_custom)

    for name in app.selected_addons:
        addon = app.addons[name]
        bundle_data.apply(addon.bundle)

    steps = list(chain(app.steps,
                       chain.from_iterable(app.addons[addon].steps
                                           for addon in app.selected_addons)))
    for step in steps:
        if not (step.bundle_add or step.bundle_remove):
            continue
        if step.bundle_remove:
            fragment = yaml.safe_load(step.bundle_remove.read_text())
            bundle_data.subtract(fragment)
        if step.bundle_add:
            fragment = yaml.safe_load(step.bundle_add.read_text())
            bundle_data.apply(fragment)

    if app.conjurefile['bundle-remove']:
        fragment = yaml.safe_load(app.conjurefile['bundle-remove'].read_text())
        bundle_data.subtract(fragment)
    if app.conjurefile['bundle-add']:
        fragment = yaml.safe_load(app.conjurefile['bundle-add'].read_text())
        bundle_data.apply(fragment)

    app.current_bundle = bundle_data
Exemple #7
0
def _setup_snap_metadata_controller():
    """ Sets metadata for a snap spell
    """
    spell_dir = Path(app.config['spell-dir'])
    bundle_filename = spell_dir / 'bundle.yaml'
    bundle_custom_filename = spell_dir / 'bundle-custom.yaml'
    if bundle_filename.exists():
        # Load bundle data early so we can merge any additional charm options
        bundle_data = Bundle(yaml.load(bundle_filename.read_text()),
                             spell_type=app.metadata.spell_type)
    else:
        bundle_data = Bundle(spell_type=app.metadata.spell_type)

    if bundle_custom_filename.exists():
        bundle_custom = yaml.load(slurp(bundle_custom_filename))
        bundle_data.apply(bundle_custom)

    for name in app.selected_addons:
        addon = app.addons[name]
        bundle_data.apply(addon.bundle)

    steps = list(
        chain(
            app.steps,
            chain.from_iterable(app.addons[addon].steps
                                for addon in app.selected_addons)))
    for step in steps:
        if not (step.bundle_add or step.bundle_remove):
            continue
        if step.bundle_remove:
            fragment = yaml.safe_load(step.bundle_remove.read_text())
            bundle_data.subtract(fragment)
        if step.bundle_add:
            fragment = yaml.safe_load(step.bundle_add.read_text())
            bundle_data.apply(fragment)

    if app.conjurefile['bundle-remove']:
        fragment = yaml.safe_load(app.conjurefile['bundle-remove'].read_text())
        bundle_data.subtract(fragment)
    if app.conjurefile['bundle-add']:
        fragment = yaml.safe_load(app.conjurefile['bundle-add'].read_text())
        bundle_data.apply(fragment)

    app.current_bundle = bundle_data