~ubuntu-branches/ubuntu/quantal/glance/quantal

« back to all changes in this revision

Viewing changes to glance/tests/functional/test_private_images.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandleman
  • Date: 2012-01-26 09:22:37 UTC
  • mfrom: (1.1.25)
  • Revision ID: package-import@ubuntu.com-20120126092237-3wvlfjtg0ut3231r
Tags: 2012.1~e3-0ubuntu1
[Chuck Short]
* New upstream version.
* debian/control: Add python-crypto as a build dependency.

[Adam Gandleman]
* debian/glance-api.install: Add policy.json

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import httplib2
21
21
import json
 
22
import os
22
23
 
23
24
from glance.tests import functional
24
25
from glance.tests.functional import keystone_utils
741
742
    bin/glance.
742
743
    """
743
744
 
744
 
    @skip_if_disabled
745
 
    def test_glance_cli(self):
746
 
        """
747
 
        Test that we can upload an owned image; that we can manipulate
748
 
        its is_public setting; and that appropriate authorization
749
 
        checks are applied to other (non-admin) users.
 
745
    def setUp(self):
 
746
        """
 
747
        Clear environment to ensure that pre-existing $OS_* variables
 
748
        do not leak into test.
 
749
        """
 
750
        self._clear_os_env()
 
751
        super(TestPrivateImagesCli, self).setUp()
 
752
 
 
753
    def _do_test_glance_cli(self, cmd):
 
754
        """
 
755
        Test that we can upload an owned image with a given command line;
 
756
        that we can manipulate its is_public setting; and that appropriate
 
757
        authorization checks are applied to other (non-admin) users.
750
758
        """
751
759
        self.cleanup()
752
760
        self.start_servers()
753
761
 
754
 
        # Add a non-public image
755
 
        cmd = ("echo testdata | bin/glance --port=%d --auth_token=%s add "
756
 
               "name=MyImage" %
757
 
               (self.api_port, keystone_utils.pattieblack_token))
758
 
        exitcode, out, err = execute(cmd)
 
762
        # Add a non-public image using the given glance command line
 
763
        exitcode, out, err = execute("echo testdata | %s" % cmd)
759
764
 
760
765
        self.assertEqual(0, exitcode)
761
766
        image_id = out.strip()[25:]
833
838
        self.assertEqual(response['x-image-meta-owner'], '')
834
839
 
835
840
        self.stop_servers()
 
841
 
 
842
    def _clear_os_env(self):
 
843
        os.environ.pop('OS_AUTH_URL', None)
 
844
        os.environ.pop('OS_AUTH_STRATEGY', None)
 
845
        os.environ.pop('OS_AUTH_USER', None)
 
846
        os.environ.pop('OS_AUTH_KEY', None)
 
847
 
 
848
    @skip_if_disabled
 
849
    def test_glance_cli_noauth_strategy(self):
 
850
        """
 
851
        Test the CLI with the noauth strategy defaulted to.
 
852
        """
 
853
        cmd = ("bin/glance --port=%d --auth_token=%s add name=MyImage" %
 
854
               (self.api_port, keystone_utils.pattieblack_token))
 
855
        self._do_test_glance_cli(cmd)
 
856
 
 
857
    @skip_if_disabled
 
858
    def test_glance_cli_keystone_strategy_switches(self):
 
859
        """
 
860
        Test the CLI with the keystone (v1) strategy enabled via
 
861
        command line switches.
 
862
        """
 
863
        substitutions = (self.api_port, self.auth_port, 'keystone',
 
864
                         'pattieblack', 'secrete')
 
865
        cmd = ("bin/glance --port=%d  --auth_url=http://localhost:%d/v1.0 "
 
866
               "--auth_strategy=%s --username=%s --password=%s "
 
867
               " add name=MyImage" % substitutions)
 
868
        self._do_test_glance_cli(cmd)
 
869
 
 
870
    @skip_if_disabled
 
871
    def test_glance_cli_keystone_strategy_environment(self):
 
872
        """
 
873
        Test the CLI with the keystone strategy enabled via
 
874
        environment variables.
 
875
        """
 
876
        os.environ['OS_AUTH_URL'] = 'http://localhost:%d/v1.0' % self.auth_port
 
877
        os.environ['OS_AUTH_STRATEGY'] = 'keystone'
 
878
        os.environ['OS_AUTH_USER'] = 'pattieblack'
 
879
        os.environ['OS_AUTH_KEY'] = 'secrete'
 
880
        cmd = "bin/glance --port=%d add name=MyImage" % self.api_port
 
881
        self._do_test_glance_cli(cmd)