~ubuntu-branches/ubuntu/vivid/neutron/vivid-updates

« back to all changes in this revision

Viewing changes to neutron/tests/tempest/common/credentials.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-03-30 11:17:19 UTC
  • mfrom: (1.1.21)
  • Revision ID: package-import@ubuntu.com-20150330111719-h0gx7233p4jkkgfh
Tags: 1:2015.1~b3-0ubuntu1
* New upstream milestone release:
  - d/control: Align version requirements with upstream.
  - d/control: Add new dependency on oslo-log.
  - d/p/*: Rebase.
  - d/control,d/neutron-plugin-hyperv*: Dropped, decomposed into
    separate project upstream.
  - d/control,d/neutron-plugin-openflow*: Dropped, decomposed into
    separate project upstream.
  - d/neutron-common.install: Add neutron-rootwrap-daemon and 
    neutron-keepalived-state-change binaries.
  - d/rules: Ignore neutron-hyperv-agent when installing; only for Windows.
  - d/neutron-plugin-cisco.install: Drop neutron-cisco-cfg-agent as
    decomposed into separate project upstream.
  - d/neutron-plugin-vmware.install: Drop neutron-check-nsx-config and
    neutron-nsx-manage as decomposed into separate project upstream.
  - d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent.
* d/pydist-overrides: Add overrides for oslo packages.
* d/control: Fixup type in package description (LP: #1263539).
* d/p/fixup-driver-test-execution.patch: Cherry pick fix from upstream VCS
  to support unit test exection in out-of-tree vendor drivers.
* d/neutron-common.postinst: Allow general access to /etc/neutron but limit
  access to root/neutron to /etc/neutron/neutron.conf to support execution
  of unit tests in decomposed vendor drivers.
* d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
 
2
#    Licensed under the Apache License, Version 2.0 (the "License");
 
3
#    you may not use this file except in compliance with the License.
 
4
#    You may obtain a copy of the License at
 
5
#
 
6
#        http://www.apache.org/licenses/LICENSE-2.0
 
7
#
 
8
#    Unless required by applicable law or agreed to in writing, software
 
9
#    distributed under the License is distributed on an "AS IS" BASIS,
 
10
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
11
#    See the License for the specific language governing permissions and
 
12
#    limitations under the License.
 
13
 
 
14
import os
 
15
 
 
16
from neutron.tests.tempest.common import accounts
 
17
from neutron.tests.tempest.common import cred_provider
 
18
from neutron.tests.tempest.common import isolated_creds
 
19
from neutron.tests.tempest import config
 
20
from neutron.tests.tempest import exceptions
 
21
 
 
22
CONF = config.CONF
 
23
 
 
24
 
 
25
# Return the right implementation of CredentialProvider based on config
 
26
# Dropping interface and password, as they are never used anyways
 
27
# TODO(andreaf) Drop them from the CredentialsProvider interface completely
 
28
def get_isolated_credentials(name, network_resources=None,
 
29
                             force_tenant_isolation=False):
 
30
    # If a test requires a new account to work, it can have it via forcing
 
31
    # tenant isolation. A new account will be produced only for that test.
 
32
    # In case admin credentials are not available for the account creation,
 
33
    # the test should be skipped else it would fail.
 
34
    if CONF.auth.allow_tenant_isolation or force_tenant_isolation:
 
35
        return isolated_creds.IsolatedCreds(
 
36
            name=name,
 
37
            network_resources=network_resources)
 
38
    else:
 
39
        if CONF.auth.locking_credentials_provider:
 
40
            # Most params are not relevant for pre-created accounts
 
41
            return accounts.Accounts(name=name)
 
42
        else:
 
43
            return accounts.NotLockingAccounts(name=name)
 
44
 
 
45
 
 
46
# We want a helper function here to check and see if admin credentials
 
47
# are available so we can do a single call from skip_checks if admin
 
48
# creds area vailable.
 
49
def is_admin_available():
 
50
    is_admin = True
 
51
    # If tenant isolation is enabled admin will be available
 
52
    if CONF.auth.allow_tenant_isolation:
 
53
        return is_admin
 
54
    # Check whether test accounts file has the admin specified or not
 
55
    elif os.path.isfile(CONF.auth.test_accounts_file):
 
56
        check_accounts = accounts.Accounts(name='check_admin')
 
57
        if not check_accounts.admin_available():
 
58
            is_admin = False
 
59
    else:
 
60
        try:
 
61
            cred_provider.get_configured_credentials('identity_admin',
 
62
                                                     fill_in=False)
 
63
        except exceptions.InvalidConfiguration:
 
64
            is_admin = False
 
65
    return is_admin