~corey.bryant/charm-helpers/drop-symlinks

« back to all changes in this revision

Viewing changes to tests/contrib/openstack/test_openstack_utils.py

  • Committer: james.page at ubuntu
  • Date: 2015-05-27 13:16:01 UTC
  • mfrom: (364.2.24 charm-helpers)
  • Revision ID: james.page@ubuntu.com-20150527131601-q8vn5oprniu5tmmq
OpenStack deploy-from-source

* Default to shallow clone for git (depth=1)
* Add Python virtualenv support for pip installs
* Pass http_proxy to pip install if specified

Show diffs side-by-side

added added

removed removed

Lines of Context:
644
644
 
645
645
    @patch.object(openstack, 'error_out')
646
646
    @patch.object(openstack, '_git_clone_and_install_single')
647
 
    def test_git_clone_and_install_errors(self, git_install_single, error_out):
 
647
    @patch.object(openstack, 'pip_create_virtualenv')
 
648
    def test_git_clone_and_install_errors(self, pip_venv, git_install_single,
 
649
                                          error_out):
648
650
        git_missing_repos = """
649
651
          repostories:
650
652
             - {name: requirements,
691
693
             - {name: requirements,
692
694
                repository: 'git://git.openstack.org/openstack/requirements',
693
695
                branch: stable/juno}"""
694
 
        openstack.git_clone_and_install(git_wrong_order_1, 'keystone')
 
696
        openstack.git_clone_and_install(git_wrong_order_1, 'keystone', depth=1)
695
697
        error_out.assert_called_with('keystone git repo must be specified last')
696
698
 
697
699
        git_wrong_order_2 = """
699
701
             - {name: keystone,
700
702
                repository: 'git://git.openstack.org/openstack/keystone',
701
703
                branch: stable/juno}"""
702
 
        openstack.git_clone_and_install(git_wrong_order_2, 'keystone')
 
704
        openstack.git_clone_and_install(git_wrong_order_2, 'keystone', depth=1)
703
705
        error_out.assert_called_with('requirements git repo must be specified first')
704
706
 
705
707
    @patch.object(openstack, 'charm_dir')
706
708
    @patch.object(openstack, 'error_out')
707
709
    @patch.object(openstack, '_git_clone_and_install_single')
708
 
    def test_git_clone_and_install_success(self, _git_install_single,
 
710
    @patch.object(openstack, 'pip_create_virtualenv')
 
711
    def test_git_clone_and_install_success(self, pip_venv, _git_install_single,
709
712
                                           error_out, charm_dir):
710
713
        proj = 'keystone'
711
714
        charm_dir.return_value = '/var/lib/juju/units/testing-foo-0/charm'
712
715
        # the following sets the global requirements_dir
713
716
        _git_install_single.return_value = '/mnt/openstack-git/requirements'
714
717
 
715
 
        openstack.git_clone_and_install(openstack_origin_git, proj)
 
718
        openstack.git_clone_and_install(openstack_origin_git, proj, depth=1)
 
719
        self.assertTrue(pip_venv.called)
716
720
        self.assertTrue(_git_install_single.call_count == 2)
717
721
        expected = [
718
722
            call('git://git.openstack.org/openstack/requirements',
719
 
                 'stable/juno', '/mnt/openstack-git',
 
723
                 'stable/juno', 1, '/mnt/openstack-git', None,
720
724
                 update_requirements=False),
721
725
            call('git://git.openstack.org/openstack/keystone',
722
 
                 'stable/juno', '/mnt/openstack-git',
 
726
                 'stable/juno', 1, '/mnt/openstack-git', None,
723
727
                 update_requirements=True)
724
728
        ]
725
729
        self.assertEquals(expected, _git_install_single.call_args_list)
737
741
                                          mkdir, join):
738
742
        repo = 'git://git.openstack.org/openstack/requirements.git'
739
743
        branch = 'master'
 
744
        depth = 1
740
745
        parent_dir = '/mnt/openstack-git/'
741
 
        dest_dir = '/mnt/openstack-git/repo-dir'
 
746
        http_proxy = 'http://squid-proxy-url'
 
747
        dest_dir = '/mnt/openstack-git'
742
748
        join.return_value = dest_dir
743
749
        path_exists.return_value = False
744
750
        install_remote.return_value = dest_dir
745
751
 
746
 
        openstack._git_clone_and_install_single(repo, branch, parent_dir, False)
 
752
        openstack._git_clone_and_install_single(repo, branch, depth, parent_dir,
 
753
                                                http_proxy, False)
747
754
        mkdir.assert_called_with(parent_dir)
748
 
        install_remote.assert_called_with(repo, dest=parent_dir,
 
755
        install_remote.assert_called_with(repo, dest=parent_dir, depth=1,
749
756
                                          branch=branch)
750
757
        assert not _git_update_reqs.called
751
 
        pip_install.assert_called_with(dest_dir)
 
758
        pip_install.assert_called_with(dest_dir, venv='/mnt/openstack-git',
 
759
                                       proxy='http://squid-proxy-url')
752
760
 
753
761
    @patch('os.path.join')
754
762
    @patch('os.mkdir')
763
771
                                                      path_exists, mkdir, join):
764
772
        repo = 'git://git.openstack.org/openstack/requirements.git'
765
773
        branch = 'master'
 
774
        depth = 1
766
775
        parent_dir = '/mnt/openstack-git/'
767
 
        dest_dir = '/mnt/openstack-git/repo-dir'
 
776
        http_proxy = 'http://squid-proxy-url'
 
777
        dest_dir = '/mnt/openstack-git'
768
778
        reqs_dir = '/mnt/openstack-git/requirements-dir'
769
779
        join.return_value = dest_dir
770
780
        openstack.requirements_dir = reqs_dir
771
781
        path_exists.return_value = False
772
782
        install_remote.return_value = dest_dir
773
783
 
774
 
        openstack._git_clone_and_install_single(repo, branch, parent_dir, True)
 
784
        openstack._git_clone_and_install_single(repo, branch, depth, parent_dir,
 
785
                                                http_proxy, True)
775
786
        mkdir.assert_called_with(parent_dir)
776
 
        install_remote.assert_called_with(repo, dest=parent_dir,
 
787
        install_remote.assert_called_with(repo, dest=parent_dir, depth=1,
777
788
                                          branch=branch)
778
789
        _git_update_reqs.assert_called_with(dest_dir, reqs_dir)
779
 
        pip_install.assert_called_with(dest_dir)
 
790
        pip_install.assert_called_with(dest_dir, venv='/mnt/openstack-git',
 
791
                                       proxy='http://squid-proxy-url')
780
792
 
781
793
    @patch('os.getcwd')
782
794
    @patch('os.chdir')