示例#1
0
 def test_create_fail_count(self):
     clt = self.client
     err = exc.BadRequest(400)
     err.message = "Request failed: too many networks."
     clt._manager.create = Mock(side_effect=err)
     nm = utils.random_unicode()
     self.assertRaises(exc.NetworkCountExceeded, clt.create, label=nm,
             cidr=example_cidr)
示例#2
0
 def test_create_fail_other(self):
     clt = self.client
     err = exc.BadRequest(400)
     err.message = "Something strange happened."
     clt._manager.create = Mock(side_effect=err)
     nm = utils.random_unicode()
     self.assertRaises(exc.BadRequest, clt.create, label=nm,
             cidr=example_cidr)
示例#3
0
 def test_create_fail_cidr_malformed(self):
     clt = self.client
     err = exc.BadRequest(400)
     err.message = "CIDR is malformed."
     clt._manager.create = Mock(side_effect=err)
     nm = utils.random_unicode()
     self.assertRaises(exc.NetworkCIDRMalformed, clt.create, label=nm,
             cidr=example_cidr)
示例#4
0
 def test_create_fail_cidr(self):
     clt = self.client
     err = exc.BadRequest(400)
     err.message = "CIDR does not contain enough addresses."
     clt._manager.create = Mock(side_effect=err)
     nm = utils.random_unicode()
     self.assertRaises(exc.NetworkCIDRInvalid, clt.create, label=nm,
             cidr=example_cidr)
示例#5
0
 def test_create_snapshot_bad_request_other(self):
     vol = self.volume
     sav = BaseManager.create
     BaseManager.create = Mock(side_effect=exc.BadRequest("FAKE"))
     name = utils.random_unicode()
     desc = utils.random_unicode()
     self.assertRaises(exc.BadRequest, vol.create_snapshot,
             name=name, description=desc, force=False)
     BaseManager.create = sav
示例#6
0
 def test_create_snapshot_bad_request(self):
     vol = self.volume
     sav = BaseManager.create
     BaseManager.create = Mock(side_effect=exc.BadRequest(
             "Invalid volume: must be available"))
     name = utils.random_unicode()
     desc = utils.random_unicode()
     self.assertRaises(exc.VolumeNotAvailable, vol.create_snapshot,
             name=name, description=desc, force=False)
     BaseManager.create = sav
示例#7
0
 def test_api_request_other_error(self):
     clt = self.client
     uri = utils.random_ascii()
     method = utils.random_ascii()
     kwargs = {"fake": utils.random_ascii()}
     err = exc.BadRequest("400", "Some other message")
     clt._time_request = Mock(side_effect=err)
     clt.management_url = utils.random_unicode()
     id_svc = clt.identity
     sav = id_svc.authenticate
     id_svc.authenticate = Mock()
     self.assertRaises(exc.BadRequest, clt._api_request, uri,
             method, **kwargs)
     id_svc.authenticate = sav
示例#8
0
 def test_api_request_missing_clt_id(self):
     clt = self.client
     uri = utils.random_ascii()
     method = utils.random_ascii()
     kwargs = {"fake": utils.random_ascii()}
     err = exc.BadRequest("400", 'The "Client-ID" header is required.')
     clt._time_request = Mock(side_effect=err)
     clt.management_url = utils.random_unicode()
     id_svc = clt.identity
     sav = id_svc.authenticate
     id_svc.authenticate = Mock()
     self.assertRaises(exc.QueueClientIDNotDefined, clt._api_request, uri,
             method, **kwargs)
     id_svc.authenticate = sav
示例#9
0
    def create_user(self, name, email, password=None, enabled=True):
        """
        ADMIN ONLY. Creates a new user for this tenant (account). The username
        and email address must be supplied. You may optionally supply the
        password for this user; if not, the API server generates a password and
        return it in the 'password' attribute of the resulting User object.
        NOTE: this is the ONLY time the password is returned; after the initial
        user creation, there is NO WAY to retrieve the user's password.

        You may also specify that the user should be created but not active by
        passing False to the enabled parameter.
        """
        # NOTE: the OpenStack docs say that the name key in the following dict
        # is supposed to be 'username', but the service actually expects 'name'.
        data = {
            "user": {
                "username": name,
                "email": email,
                "enabled": enabled,
            }
        }
        if password:
            data["user"]["OS-KSADM:password"] = password
        resp, resp_body = self.method_post("users", data=data, admin=True)
        if resp.status_code == 201:
            return User(self, resp_body.get("user", resp_body))
        elif resp.status_code in (401, 403, 404):
            raise exc.AuthorizationFailure("You are not authorized to create "
                                           "users.")
        elif resp.status_code == 409:
            raise exc.DuplicateUser("User '%s' already exists." % name)
        elif resp.status_code == 400:
            message = resp_body["badRequest"]["message"]
            if "Expecting valid email address" in message:
                raise exc.InvalidEmail("%s is not valid" % email)
            else:
                raise exc.BadRequest(message)
示例#10
0
 def test_create_volume_fail_other(self):
     mgr = self.client._manager
     mgr._create = Mock(side_effect=exc.BadRequest(400, "FAKE"))
     self.assertRaises(exc.BadRequest, mgr.create, "name",
             size=MIN_SIZE, clone_id=utils.random_unicode())
示例#11
0
 def test_create_volume_bad_clone_size(self):
     mgr = self.client._manager
     mgr._create = Mock(side_effect=exc.BadRequest(400,
             "Clones currently must be >= original volume size"))
     self.assertRaises(exc.VolumeCloneTooSmall, mgr.create, "name",
             size=MIN_SIZE, clone_id=utils.random_unicode())