Ejemplo n.º 1
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], ), {}),
        ])
Ejemplo 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)
Ejemplo 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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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]])
Ejemplo n.º 6
0
 def test_init(self):
     step = Add()
     self.assertEqual(step.step_id, constants.IMPORT_STEP_ADD_UNITS)
     self.assertTrue(step.description is not None)
Ejemplo n.º 7
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])