(self)
| 34 | """ |
| 35 | |
| 36 | def setUp(self): |
| 37 | self.apiclient = self.testClient.getApiClient() |
| 38 | self.dbclient = self.testClient.getDbConnection() |
| 39 | self.mgtSvrDetails = self.config.__dict__["mgtSvr"][0].__dict__ |
| 40 | self.cleanup = [] |
| 41 | self.testdata = { |
| 42 | "account": { |
| 43 | "email": "mtu@test.cloud", |
| 44 | "firstname": "Marvin", |
| 45 | "lastname": "TestUser", |
| 46 | "username": "staticrole_acctest-", |
| 47 | "password": "password", |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | feature_enabled = self.apiclient.listCapabilities(listCapabilities.listCapabilitiesCmd()).dynamicrolesenabled |
| 52 | if feature_enabled: |
| 53 | self.skipTest("Dynamic role-based API checker is enabled, skipping tests for static role-base API checker") |
| 54 | |
| 55 | commandsProperties = [] |
| 56 | try: |
| 57 | sshClient = SshClient( |
| 58 | self.mgtSvrDetails["mgtSvrIp"], |
| 59 | 22, |
| 60 | self.mgtSvrDetails["user"], |
| 61 | self.mgtSvrDetails["passwd"], |
| 62 | retries=1, |
| 63 | log_lvl=logging.INFO |
| 64 | ) |
| 65 | result = sshClient.runCommand("cat /etc/cloudstack/management/commands.properties") |
| 66 | if 'status' in result and result['status'] == 'SUCCESS' and 'stdout' in result and len(result['stdout']) > 0: |
| 67 | commandsProperties = result['stdout'] |
| 68 | except Exception: |
| 69 | self.debug("Failed to ssh into mgmt server host and grab commands.properties file") |
| 70 | testDir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) |
| 71 | localFileName = os.path.abspath(testDir + "/../../../client/conf/commands.properties.in") |
| 72 | if os.path.isfile(localFileName): |
| 73 | self.info("Detected that we're running in developer mode with maven, using file at:" + localFileName) |
| 74 | with open(localFileName) as f: |
| 75 | commandsProperties = f.readlines() |
| 76 | |
| 77 | if len(commandsProperties) < 1: |
| 78 | self.skipTest("Unable to find commands.properties, skipping this test") |
| 79 | |
| 80 | apiMap = {} |
| 81 | for line in commandsProperties: |
| 82 | if not line or line == '' or line == '\n' or line.startswith('#'): |
| 83 | continue |
| 84 | name, value = line.split('=') |
| 85 | apiMap[name.strip()] = value.strip() |
| 86 | |
| 87 | self.roleApiMap = {} # role to list of apis allowed |
| 88 | octetKey = {'Admin':1, 'DomainAdmin':4, 'User':8} |
| 89 | for role in list(octetKey.keys()): |
| 90 | for api in sorted(apiMap.keys()): |
| 91 | if (octetKey[role] & int(apiMap[api])) > 0: |
| 92 | if role not in self.roleApiMap: |
| 93 | self.roleApiMap[role] = [] |
nothing calls this directly
no test coverage detected