示例#1
0
    def test_add_pass_through(self):

        # Add a passthrough section
        self.data['inputModel']['pass-through'] = {}
        self.data['inputModel']['pass-through']['global'] = {}
        self.data['inputModel']['pass-through']['global']['foo'] = 'bar'

        # Write the changes
        changes = model.write_model(self.data, self.model_dir, dry_run=True)

        changed = {
            k: v
            for k, v in changes.items() if v['status'] != model.IGNORED
        }
        self.assertEqual(1, len(changed))

        info = next(six.itervalues(changed))
        self.assertEqual(model.ADDED, info['status'])

        filename = next(six.iterkeys(changed))

        # Should create some random filename that begins with pass-through
        self.assertTrue(filename.startswith('data/pass_through_'))

        self.assertIn('foo', info['data']['pass-through']['global'])
示例#2
0
    def test_no_changes(self):
        changes = model.write_model(self.data, self.model_dir, dry_run=True)

        affected_files = [
            k for k, v in changes.items() if v['status'] != model.IGNORED
        ]
        self.assertEqual(0, len(affected_files))
示例#3
0
    def test_add_pass_through(self):

        # Modify one value in the existing pass-through.global dict
        self.data['inputModel']['pass-through']['global']['foo'] = 'bar'

        # And create a brand new section in pass-through
        self.data['inputModel']['pass-through']['newsection'] = 'baz'

        # Write the changes
        changes = model.write_model(self.data, self.model_dir, dry_run=True)

        # All pass_through contents should be written to the existing file
        changed = {
            k: v
            for k, v in changes.items() if v['status'] != model.IGNORED
        }
        self.assertEqual(1, len(changed))

        info = next(six.itervalues(changed))
        self.assertEqual(model.CHANGED, info['status'])

        filename = next(six.iterkeys(changed))
        self.assertEqual('data/pass_through.yml', filename)

        self.assertIn('foo', info['data']['pass-through']['global'])
        self.assertIn('newsection', info['data']['pass-through'])
示例#4
0
    def test_add_disk_models(self):
        num_to_add = 5
        # grab last disk model and make extra copies of it
        disk_model = self.data['inputModel']['disk-models'][-1:][0]
        for i in range(0, num_to_add):
            clone = copy.deepcopy(disk_model)
            clone['name'] = 'model-%s' % i
            self.data['inputModel']['disk-models'].append(clone)

        changes = model.write_model(self.data, self.model_dir, dry_run=True)
        added_files = [
            k for k, v in changes.items() if v['status'] == model.ADDED
        ]

        self.assertEqual(num_to_add, len(added_files))
示例#5
0
    def test_delete_list(self):
        self.data['inputModel'].pop('control-planes')

        # Write the changes
        changes = model.write_model(self.data, self.model_dir, dry_run=True)

        changed = {
            k: v
            for k, v in changes.items() if v['status'] != model.IGNORED
        }
        self.assertEqual(1, len(changed))

        info = next(six.itervalues(changed))
        self.assertEqual(model.DELETED, info['status'])

        self.assertIn('data/control_plane.yml', changed)
示例#6
0
    def test_update_dict(self):
        # Modify the 'cloud' section, which is part of cloudConfig.yml
        self.data['inputModel']['cloud']['foo'] = 'bar'

        # Write the changes
        changes = model.write_model(self.data, self.model_dir, dry_run=True)

        changed = {
            k: v
            for k, v in changes.items() if v['status'] != model.IGNORED
        }
        self.assertEqual(1, len(changed))

        self.assertIn('cloudConfig.yml', changed)

        info = next(six.itervalues(changed))
        self.assertEqual(model.CHANGED, info['status'])
示例#7
0
    def test_delete_pass_through(self):
        # Delete the only value in one of the pass-through sections
        self.data['inputModel'].pop('pass-through')

        # Write the changes
        changes = model.write_model(self.data, self.model_dir, dry_run=True)

        changed = {
            k: v
            for k, v in changes.items() if v['status'] != model.IGNORED
        }
        self.assertEqual(1, len(changed))

        info = next(six.itervalues(changed))
        self.assertEqual(model.DELETED, info['status'])

        filename = next(six.iterkeys(changed))
        self.assertEqual('data/pass_through.yml', filename)
示例#8
0
    def test_update_pass_through(self):
        # Modify one of the values in data/neutron_passthrough.yml
        self.data['inputModel']['pass-through']['global']['esx_cloud2'] = False

        # Write the changes
        changes = model.write_model(self.data, self.model_dir, dry_run=True)

        changed = {
            k: v
            for k, v in changes.items() if v['status'] != model.IGNORED
        }
        self.assertEqual(1, len(changed))

        info = next(six.itervalues(changed))
        self.assertEqual(model.CHANGED, info['status'])

        self.assertIn('data/neutron_passthrough.yml', changed)
        self.assertIn('esx_cloud2', info['data']['pass-through']['global'])
示例#9
0
    def test_add_to_uneven_split(self):
        # Manipulate the model to make it appear that the 3 disk-models are
        # distributed over just 2 files rather than 3.
        source = 'data/disks_compute.yml'
        dest = 'data/disks_controller_1TB.yml'
        model_name = 'COMPUTE-DISKS'

        # Move the model to one of the other file sections
        self.data['fileInfo']['fileSectionMap'].pop(source)

        for section in self.data['fileInfo']['fileSectionMap'][dest]:
            if isinstance(section, dict) and 'disk-models' in section:
                section['disk-models'].append(model_name)
                break

        self.data['fileInfo']['files'] = [
            f for f in self.data['fileInfo']['files'] if f != source
        ]
        self.data['fileInfo']['sections']['disk-models'] = [
            f for f in self.data['fileInfo']['sections']['disk-models']
            if f != source
        ]

        # Now add 2 disk-models
        self.data['inputModel']['disk-models'].append({"name": "FOO"})
        self.data['inputModel']['disk-models'].append({"name": "BAR"})

        # Write the changes
        changes = model.write_model(self.data, self.model_dir, dry_run=True)

        # There should be one file added with two disk models
        added = {
            k: v
            for k, v in changes.items() if v['status'] == model.ADDED
        }

        # Remove the product for comparison to the added data
        new_data = next(six.itervalues(added))['data']

        # Should have 2 new disk models in the file (FOO and BAR)
        self.assertEqual(['FOO', 'BAR'],
                         [f['name'] for f in new_data['disk-models']])
示例#10
0
    def test_add_servers(self):
        before_len = len(self.data['inputModel']['servers'])

        num_to_add = 5
        # grab last server and make extra copies of it
        server = self.data['inputModel']['servers'][-1:][0]
        for i in range(0, num_to_add):
            clone = copy.deepcopy(server)
            clone['id'] = 'server-%s' % i
            self.data['inputModel']['servers'].append(clone)

        changes = model.write_model(self.data, self.model_dir, dry_run=True)
        changed_files = [
            k for k, v in changes.items() if v['status'] == model.CHANGED
        ]

        self.assertEqual(1, len(changed_files))
        self.assertEqual(changed_files[0], "data/servers.yml")
        after_len = len(changes[changed_files[0]]['data']['servers'])
        self.assertEqual(before_len + num_to_add, after_len)
示例#11
0
    def test_add_new_list(self):
        added_list = {'foo': [{'name': 'bar'}, {'name': 'baz'}]}
        self.data['inputModel'].update(added_list)

        # Write the changes
        changes = model.write_model(self.data, self.model_dir, dry_run=True)

        changed = {
            k: v
            for k, v in changes.items() if v['status'] != model.IGNORED
        }
        self.assertEqual(1, len(changed))

        info = next(six.itervalues(changed))
        self.assertEqual(model.ADDED, info['status'])

        # Remove the product for comparison to the added data
        new_data = next(six.itervalues(changed))['data']
        new_data.pop('product')

        self.assertEqual(added_list, new_data)