Exemplo n.º 1
0
 def test_link(self, fake_link):
     target = 'path-1'
     link_path = 'path-2'
     step = Add()
     unit = Mock(storage_path=link_path)
     step.parent = Mock(storage_path=target)
     step.link(unit)
     fake_link.assert_called_with(target, link_path)
Exemplo n.º 2
0
 def test_link(self, fake_link):
     target = 'path-1'
     link_path = 'path-2'
     step = Add()
     unit = Mock(storage_path=link_path)
     step.parent = Mock(storage_path=target)
     step.link(unit)
     fake_link.assert_called_with(target, link_path)
Exemplo n.º 3
0
    def test_link_error(self, fake_link, fake_islink, fake_readlink):
        target = 'path-1'
        link_path = 'path-2'
        step = Add()
        unit = Mock(storage_path=link_path)
        step.parent = Mock(storage_path=target)
        fake_link.side_effect = OSError(errno.EPERM, link_path)

        # test
        self.assertRaises(OSError, step.link, unit)

        # validation
        self.assertFalse(fake_islink.called)
        self.assertFalse(fake_readlink.called)
Exemplo n.º 4
0
    def test_process_main(self, fake_associate, fake_model, fake_lib):
        repo_id = 'r-1234'
        remote_id = 'remote-1'
        refs = [
            Mock(path='branch:1', commit='commit:1', metadata='md:1'),
            Mock(path='branch:2', commit='commit:2', metadata='md:2'),
            Mock(path='branch:3', commit='commit:3', metadata='md:3'),
            Mock(path='branch:4', commit='commit:4', metadata='md:4'),
            Mock(path='branch:5', commit='commit:5', metadata='md:5'),
        ]
        units = [Mock(ref=r, unit_key={}) for r in refs]
        units[0].save.side_effect = NotUniqueError  # duplicate

        fake_model.Branch.side_effect = units
        fake_model.Branch.objects.get.return_value = units[0]

        branches = [r.path for r in refs[:-1]]

        repository = Mock()
        repository.list_refs.return_value = refs
        fake_lib.Repository.return_value = repository

        parent = Mock(remote_id=remote_id, storage_dir='/tmp/xyz', branches=branches)
        parent.get_repo.return_value = Mock(repo_id=repo_id)

        fake_conduit = Mock()

        # test
        step = Add()
        step.parent = parent
        step.get_conduit = Mock(return_value=fake_conduit)
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_dir)
        self.assertEqual(
            fake_model.Branch.call_args_list,
            [
                ((), dict(
                    remote_id=remote_id,
                    branch=r.path,
                    commit=r.commit,
                    metadata=r.metadata))
                for r in refs[:-1]
            ])
        self.assertEqual(
            fake_associate.call_args_list,
            [
                ((parent.get_repo.return_value, u), {}) for u in units[:-1]
            ])
Exemplo n.º 5
0
    def test_link_error(self, fake_link, fake_islink, fake_readlink):
        target = 'path-1'
        link_path = 'path-2'
        step = Add()
        unit = Mock(storage_path=link_path)
        step.parent = Mock(storage_path=target)
        fake_link.side_effect = OSError(errno.EPERM, link_path)

        # test
        self.assertRaises(OSError, step.link, unit)

        # validation
        self.assertFalse(fake_islink.called)
        self.assertFalse(fake_readlink.called)
Exemplo n.º 6
0
    def test_link_exists_wrong_target(self, fake_link, fake_islink, fake_readlink):
        target = 'path-1'
        link_path = 'path-2'
        step = Add()
        unit = Mock(storage_path=link_path)
        step.parent = Mock(storage_path=target)
        fake_islink.return_value = True
        fake_readlink.return_value = 'not-target'
        fake_link.side_effect = OSError(errno.EEXIST, link_path)

        # test
        self.assertRaises(OSError, step.link, unit)

        # validation
        fake_islink.assert_called_with(link_path)
        fake_readlink.assert_called_with(link_path)
Exemplo n.º 7
0
    def test_link_exists_not_link(self, fake_link, fake_islink, fake_readlink):
        target = 'path-1'
        link_path = 'path-2'
        step = Add()
        unit = Mock(storage_path=link_path)
        step.parent = Mock(storage_path=target)
        fake_islink.return_value = False
        fake_readlink.return_value = target
        fake_link.side_effect = OSError(errno.EEXIST, link_path)

        # test
        self.assertRaises(OSError, step.link, unit)

        # validation
        fake_islink.assert_called_with(link_path)
        self.assertFalse(fake_readlink.called)
Exemplo n.º 8
0
    def test_process_main(self, fake_associate, fake_model, fake_lib):
        repo_id = "r-1234"
        remote_id = "remote-1"
        refs = [
            Mock(path="branch:1", commit="commit:1", metadata="md:1"),
            Mock(path="branch:2", commit="commit:2", metadata="md:2"),
            Mock(path="branch:3", commit="commit:3", metadata="md:3"),
            Mock(path="branch:4", commit="commit:4", metadata="md:4"),
            Mock(path="branch:5", commit="commit:5", metadata="md:5"),
        ]
        units = [Mock(ref=r, unit_key={}) for r in refs]
        units[0].save.side_effect = NotUniqueError  # duplicate

        fake_model.Branch.side_effect = units
        fake_model.Branch.objects.get.return_value = units[0]

        branches = [r.path.split(":")[-1] for r in refs[:-1]]

        repository = Mock()
        repository.list_refs.return_value = refs
        fake_lib.Repository.return_value = repository

        parent = Mock(remote_id=remote_id, storage_dir="/tmp/xyz", branches=branches)
        parent.get_repo.return_value = Mock(id=repo_id)

        fake_conduit = Mock()

        # test
        step = Add()
        step.parent = parent
        step.get_conduit = Mock(return_value=fake_conduit)
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_dir)
        self.assertEqual(
            fake_model.Branch.call_args_list,
            [
                ((), dict(remote_id=remote_id, branch=r.path.split(":")[-1], commit=r.commit, metadata=r.metadata))
                for r in refs[:-1]
            ],
        )
        self.assertEqual(
            fake_associate.call_args_list, [((parent.get_repo.return_value.repo_obj, u), {}) for u in units[:-1]]
        )
Exemplo n.º 9
0
    def test_process_main(self, fake_unit, fake_link, fake_model, fake_lib):
        remote_id = 'remote-1'
        commits = [Mock(), Mock()]
        refs = [
            Mock(path='branch:1', commit='commit:1', metadata='md:1'),
            Mock(path='branch:2', commit='commit:2', metadata='md:2'),
            Mock(path='branch:3', commit='commit:3', metadata='md:3')
        ]
        units = [
            Mock(key='key:1', metadata=refs[0].metadata,
                 storage_path='path:1'),
            Mock(key='key:2', metadata=refs[1].metadata, storage_path='path:2')
        ]
        pulp_units = [Mock(), Mock()]

        branches = [r.path for r in refs[:-1]]

        repository = Mock()
        repository.list_refs.return_value = refs
        fake_lib.Repository.return_value = repository

        fake_model.Commit.side_effect = commits
        fake_model.Unit.side_effect = units

        fake_unit.side_effect = pulp_units

        fake_conduit = Mock()

        # test
        step = Add()
        step.parent = Mock(remote_id=remote_id,
                           storage_path='/tmp/xyz',
                           branches=branches)
        step.get_conduit = Mock(return_value=fake_conduit)
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_path)
        self.assertEqual(fake_model.Commit.call_args_list, [
            (('commit:1', 'md:1'), {}),
            (('commit:2', 'md:2'), {}),
        ])
        self.assertEqual(fake_model.Unit.call_args_list, [
            ((remote_id, 'branch:1', commits[0]), {}),
            ((remote_id, 'branch:2', commits[1]), {}),
        ])
        self.assertEqual(fake_link.call_args_list, [
            ((units[0], ), {}),
            ((units[1], ), {}),
        ])
        self.assertEqual(fake_unit.call_args_list, [
            ((Unit.TYPE_ID, units[0].key, units[0].metadata,
              units[0].storage_path), {}),
            ((Unit.TYPE_ID, units[1].key, units[1].metadata,
              units[1].storage_path), {}),
        ])
        self.assertEqual(fake_conduit.save_unit.call_args_list, [
            ((pulp_units[0], ), {}),
            ((pulp_units[1], ), {}),
        ])
Exemplo n.º 10
0
    def test_find_branches(self, fake_walk, fake_open, fake_head):
        fp = Mock()
        fp.__enter__ = Mock(return_value=fp)
        fp.__exit__ = Mock()
        fp.read.side_effect = ['hash-1', 'hash-2']
        fake_open.return_value = fp
        path = '/path-1'
        step = Add()
        step.parent = Mock(storage_path=path)
        heads = [Mock(), Mock()]
        fake_head.side_effect = heads
        tree = [
            ('/path-1/refs/heads', ['fedora'], []),
            ('/path-1/refs/heads/fedora', ['f21'], []),
            ('/path-1/refs/heads/fedora/f21', ['i386', 'x86_64'], []),
            ('/path-1/refs/heads/fedora/f21/i386', [], ['os']),
            ('/path-1/refs/heads/fedora/f21/x86_64', [], ['os']),
        ]
        fake_walk.return_value = tree

        # test
        branches = list(step.find_branches())

        # validation
        self.assertEqual(
            fake_open.call_args_list,
            [
                (('/path-1/refs/heads/fedora/f21/i386/os',), {}),
                (('/path-1/refs/heads/fedora/f21/x86_64/os',), {})
            ])
        fake_walk.assert_called_once_with(os.path.join(path, 'refs', 'heads'))
        self.assertEqual(
            fake_head.call_args_list,
            [
                (('fedora/f21/i386/os', 'hash-1'), {}),
                (('fedora/f21/x86_64/os', 'hash-2'), {})
            ])
        self.assertEqual(len(branches), 2)
        self.assertEqual(branches, heads)
Exemplo n.º 11
0
    def test_process_main(self, fake_associate, fake_model, fake_lib):
        repo_id = 'r-1234'
        remote_id = 'remote-1'
        refs = [
            Mock(path='branch:1', commit='commit:1', metadata='md:1'),
            Mock(path='branch:2', commit='commit:2', metadata='md:2'),
            Mock(path='branch:3', commit='commit:3', metadata='md:3'),
            Mock(path='branch:4', commit='commit:4', metadata='md:4'),
            Mock(path='branch:5', commit='commit:5', metadata='md:5'),
        ]
        units = [Mock(ref=r, unit_key={}) for r in refs]
        units[0].save.side_effect = NotUniqueError  # duplicate

        fake_model.Branch.side_effect = units
        fake_model.Branch.objects.get.return_value = units[0]

        branches = [r.path.split(':')[-1] for r in refs[:-1]]

        repository = Mock()
        repository.list_refs.return_value = refs
        fake_lib.Repository.return_value = repository

        parent = Mock(remote_id=remote_id,
                      storage_dir='/tmp/xyz',
                      branches=branches)
        parent.get_repo.return_value = Mock(id=repo_id)

        fake_conduit = Mock()

        # test
        step = Add()
        step.parent = parent
        step.get_conduit = Mock(return_value=fake_conduit)
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_dir)
        self.assertEqual(fake_model.Branch.call_args_list,
                         [((),
                           dict(remote_id=remote_id,
                                branch=r.path.split(':')[-1],
                                commit=r.commit,
                                metadata=r.metadata)) for r in refs[:-1]])
        self.assertEqual(fake_associate.call_args_list,
                         [((parent.get_repo.return_value.repo_obj, u), {})
                          for u in units[:-1]])
Exemplo n.º 12
0
    def test_process_main(self, fake_refs, fake_repo, dt, fake_unit):
        utc_now = 'utc-now'
        dt.utcnow.return_value = utc_now
        refs = Mock()
        fake_refs.return_value = refs
        heads = [Mock(), Mock()]
        remote_id = 'remote-1'
        repo = Mock(TYPE_ID='type-id',
                    unit_key='unit-key',
                    metadata='md',
                    storage_path='storage-path')
        fake_repo.return_value = repo
        unit = Mock()
        fake_unit.return_value = unit
        fake_conduit = Mock()

        # test
        step = Add()
        step.find_branches = Mock(return_value=heads)
        step.parent = Mock(remote_id=remote_id)
        step.link = Mock()
        step.get_conduit = Mock(return_value=fake_conduit)
        step.process_main()

        # validation
        dt.utcnow.assert_called_once_with()
        fake_refs.assert_called_once_with()
        step.find_branches.assert_called_once_with()
        self.assertEqual(
            refs.add_head.call_args_list,
            [
                ((heads[0],), {}),
                ((heads[1],), {}),
            ])
        fake_repo.assert_called_once_with(remote_id, fake_refs.return_value, utc_now)
        step.link.assert_called_once_with(repo)
        fake_unit.assert_called_once_with(
            repo.TYPE_ID, repo.unit_key, repo.metadata, repo.storage_path)
        fake_conduit.save_unit.assert_called_once_with(unit)
Exemplo n.º 13
0
 def test_init(self):
     step = Add()
     self.assertEqual(step.step_id, constants.IMPORT_STEP_ADD_UNITS)
     self.assertTrue(step.description is not None)
Exemplo n.º 14
0
    def test_process_main(self, fake_unit, fake_link, fake_model, fake_lib):
        remote_id = 'remote-1'
        commits = [
            Mock(),
            Mock()
        ]
        refs = [
            Mock(path='branch:1', commit='commit:1', metadata='md:1'),
            Mock(path='branch:2', commit='commit:2', metadata='md:2')
        ]
        units = [
            Mock(key='key:1', metadata=refs[0].metadata, storage_path='path:1'),
            Mock(key='key:2', metadata=refs[1].metadata, storage_path='path:2')
        ]
        pulp_units = [
            Mock(),
            Mock()
        ]

        repository = Mock()
        repository.list_refs.return_value = refs
        fake_lib.Repository.return_value = repository

        fake_model.Commit.side_effect = commits
        fake_model.Unit.side_effect = units

        fake_unit.side_effect = pulp_units

        fake_conduit = Mock()

        # test
        step = Add()
        step.parent = Mock(remote_id=remote_id, storage_path='/tmp/xyz')
        step.get_conduit = Mock(return_value=fake_conduit)
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_path)
        self.assertEqual(
            fake_model.Commit.call_args_list,
            [
                (('commit:1', 'md:1'), {}),
                (('commit:2', 'md:2'), {}),
            ])
        self.assertEqual(
            fake_model.Unit.call_args_list,
            [
                ((remote_id, 'branch:1', commits[0]), {}),
                ((remote_id, 'branch:2', commits[1]), {}),
            ])
        self.assertEqual(
            fake_link.call_args_list,
            [
                ((units[0],), {}),
                ((units[1],), {}),
            ])
        self.assertEqual(
            fake_unit.call_args_list,
            [
                ((Unit.TYPE_ID, units[0].key, units[0].metadata, units[0].storage_path), {}),
                ((Unit.TYPE_ID, units[1].key, units[1].metadata, units[1].storage_path), {}),
            ])
        self.assertEqual(
            fake_conduit.save_unit.call_args_list,
            [
                ((pulp_units[0],), {}),
                ((pulp_units[1],), {}),
            ])
Exemplo n.º 15
0
    def test_process_main(self, fake_associate, fake_model, fake_lib):
        def history(commit_id):
            return [
                Commit(id='{}head'.format(commit_id), metadata={'md': 0}),
                Commit(id='{}parent-1'.format(commit_id), metadata={'md': 1}),
                Commit(id='{}parent-2'.format(commit_id), metadata={'md': 2}),
            ]

        repo_id = 'r-1234'
        remote_id = 'remote-1'
        refs = [
            Mock(path='branch:1', commit='commit:1', metadata='md:1'),
            Mock(path='branch:2', commit='commit:2', metadata='md:2'),
            Mock(path='branch:3', commit='commit:3', metadata='md:3'),
            Mock(path='branch:4', commit='commit:4', metadata='md:4'),
            Mock(path='branch:5', commit='commit:5', metadata='md:5'),
        ]

        units = [
            Mock(remote_id=remote_id,
                 branch=r.path.split(':')[-1],
                 commit=c.id,
                 metadata=c.metadata,
                 unit_key={}) for r in refs[:-1]
            for c in reversed(history(r.commit))
        ]

        units[0].save.side_effect = NotUniqueError  # duplicate

        fake_model.Branch.side_effect = units
        fake_model.Branch.objects.get.return_value = units[0]

        branches = [r.path.split(':')[-1] for r in refs[:-1]]

        repository = Mock()
        repository.list_refs.return_value = refs
        repository.history.side_effect = history
        fake_lib.Repository.return_value = repository

        parent = Mock(remote_id=remote_id,
                      storage_dir='/tmp/xyz',
                      branches=branches)
        parent.get_repo.return_value = Mock(id=repo_id)

        fake_conduit = Mock()

        # test
        step = Add()
        step.parent = parent
        step.get_conduit = Mock(return_value=fake_conduit)
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_dir)
        self.assertEqual(fake_model.Branch.call_args_list, [
            call(remote_id=u.remote_id,
                 branch=u.branch,
                 commit=u.commit,
                 metadata=u.metadata) for u in units
        ])
        self.assertEqual(fake_associate.call_args_list,
                         [((parent.get_repo.return_value.repo_obj, u), {})
                          for u in units])