Esempio n. 1
0
    def test_new_unit(self, unit):
        document = Mock()

        # test
        plan = Plan(Mock(), tuple(), False)
        created = plan._new_unit(document)

        # validation
        unit.assert_called_once_with(plan, document)
        self.assertEqual(created, unit.return_value)
Esempio n. 2
0
    def test_new_unit(self, unit):
        document = Mock()

        # test
        plan = Plan(Mock(), tuple(), False)
        created = plan._new_unit(document)

        # validation
        unit.assert_called_once_with(plan, document)
        self.assertEqual(created, unit.return_value)
Esempio n. 3
0
    def test_new_path_directory(self, content_dir):
        digest = '0123456789'
        content_dir.return_value = '/tmp/path_1'
        unit = Mock(type_id='iso', storage_path='/tmp/path_1/foo.iso')
        unit.key_digest.return_value = digest

        # test
        plan = Plan(Mock(), tuple(), False)
        path = plan._new_path(unit)

        # validation
        expected_path = os.path.join(
            os.path.join(content_dir.return_value, 'units'), unit.type_id,
            digest[0:2], digest[2:])
        self.assertEqual(path, expected_path)
Esempio n. 4
0
    def test_migrate(self, path_exists, mkdir, shutil):
        unit_id = '123'
        path = '/tmp/old/path_1'
        new_path = '/tmp/new/content/path_2'
        path_exists.return_value = True

        # test
        plan = Plan(Mock(), tuple(), False)
        plan.migrate(unit_id, path, new_path)

        # validation
        path_exists.assert_called_once_with(path)
        mkdir.assert_called_once_with(os.path.dirname(new_path))
        shutil.move.assert_called_once_with(path, new_path)
        plan.collection.update_one.assert_called_once_with(
            filter={'_id': unit_id},
            update={'$set': {'_storage_path': new_path}})
    def test_migrate(self, path_exists, mkdir, shutil):
        unit_id = '123'
        path = '/tmp/old/path_1'
        new_path = '/tmp/new/content/path_2'
        path_exists.return_value = True

        # test
        plan = Plan(Mock(), tuple(), False)
        plan.migrate(unit_id, path, new_path)

        # validation
        path_exists.assert_called_once_with(path)
        mkdir.assert_called_once_with(os.path.dirname(new_path))
        shutil.move.assert_called_once_with(path, new_path)
        plan.collection.update_one.assert_called_once_with(
            filter={'_id': unit_id},
            update={'$set': {'_storage_path': new_path}})
Esempio n. 6
0
    def test_new_path_directory(self, content_dir):
        digest = '0123456789'
        content_dir.return_value = '/tmp/path_1'
        unit = Mock(type_id='iso', storage_path='/tmp/path_1/foo.iso')
        unit.key_digest.return_value = digest

        # test
        plan = Plan(Mock(), tuple(), False)
        path = plan._new_path(unit)

        # validation
        expected_path = os.path.join(
            os.path.join(content_dir.return_value, 'units'),
            unit.type_id,
            digest[0:2],
            digest[2:])
        self.assertEqual(path, expected_path)
def image_plan():
    """
    Factory to create an image migration plan.

    :return: A configured plan.
    :rtype: Plan
    """
    key_fields = ('image_id',)
    collection = connection.get_collection('units_docker_image')
    return Plan(collection, key_fields, join_leaf=False)
Esempio n. 8
0
def distribution_plan():
    """
    Factory to create an Distribution migration plan.

    :return: A configured plan.
    :rtype: Plan
    """
    key_fields = ('distribution_id', 'family', 'variant', 'version', 'arch')
    collection = connection.get_collection('units_distribution')
    return Plan(collection, key_fields, join_leaf=False)
Esempio n. 9
0
def module_plan():
    """
    Factory to create an puppet module migration plan.

    :return: A configured plan.
    :rtype: Plan
    """
    key_fields = ('author', 'name', 'version')
    collection = connection.get_collection('units_puppet_module')
    return Plan(collection, key_fields)
Esempio n. 10
0
def yum_metadata_plan():
    """
    Factory to create an YUM metadata migration plan.

    :return: A configured plan.
    :rtype: Plan
    """
    key_fields = ('data_type', 'repo_id')
    collection = connection.get_collection('units_yum_repo_metadata_file')
    return Plan(collection, key_fields)
def manifest_plan():
    """
    Factory to create a manifest migration plan.

    :return: A configured plan.
    :rtype: Plan
    """
    key_fields = ('digest', )
    collection = connection.get_collection('units_docker_manifest')
    return Plan(collection, key_fields)
Esempio n. 12
0
def iso_plan():
    """
    Factory to create an ISO migration plan.

    :return: A configured plan.
    :rtype: Plan
    """
    key_fields = ('name', 'checksum', 'size')
    collection = connection.get_collection('units_iso')
    return Plan(collection, key_fields)
def drpm_plan():
    """
    Factory to create an DRPM migration plan.

    :return: A configured plan.
    :rtype: Plan
    """
    key_fields = ('epoch', 'version', 'release', 'filename', 'checksumtype',
                  'checksum')
    collection = connection.get_collection('units_drpm')
    return Plan(collection, key_fields)
def package_plan(collection):
    """
    Factory to create a package migration plan.

    :param collection: A package collection.
    :type collection: pymongo.collection.Collection
    :return: A configured plan.
    :rtype: Plan
    """
    key_fields = ('name', 'epoch', 'version', 'release', 'arch',
                  'checksumtype', 'checksum')
    return Plan(collection, key_fields)
Esempio n. 15
0
    def test_init(self):
        collection = Mock()
        key_fields = ('name', 'version')
        join_leaf = Mock()

        # test
        plan = Plan(collection, key_fields, join_leaf)

        # validation
        self.assertEqual(plan.collection, collection)
        self.assertEqual(plan.key_fields, key_fields)
        self.assertEqual(plan.join_leaf, join_leaf)
        self.assertEqual(plan.fields, set())
Esempio n. 16
0
    def test_iter(self, new_path, unit):
        collection = Mock()
        key_fields = ('name', 'version')
        documents = [
            Mock(_id='1'),
            Mock(_id='2'),
            Mock(_id='3'),
            Mock(_id='4')
        ]
        collection.find.return_value = documents
        units = [
            Mock(id='1', needs_migration=Mock(return_value=True)),
            Mock(id='2', needs_migration=Mock(return_value=False)),
            Mock(id='3', needs_migration=Mock(return_value=True)),
            Mock(id='4', needs_migration=Mock(return_value=False)),
        ]
        unit.side_effect = units
        new_paths = [
            'p1',
            'p2',
            'p3',
            'p4'
        ]
        new_path.side_effect = new_paths

        # test
        plan = Plan(collection, key_fields)
        plan.fields.add('release')
        _list = list(plan)

        # validation
        collection.find.assert_called_once_with(
            projection={
                '_storage_path': True,
                '_content_type_id': True,
                'version': True,
                'release': True,
                'name': True,
            })
        self.assertEqual(
            unit.call_args_list,
            [
                call(plan, d) for d in documents
            ])
        for unit, new_path in izip(units, new_paths):
            self.assertEqual(unit.new_path, new_path)
        self.assertEqual(_list, [u for u in units if u.needs_migration()])
Esempio n. 17
0
def msm_plan():
    collection = connection.get_collection('units_msm')
    key_fields = ("name", "version", "checksumtype", "checksum")
    return Plan(collection, key_fields)