-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add tests
- Loading branch information
Showing
227 changed files
with
20,795 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## OpenvCloud Functional Tests | ||
|
||
Please only put **internal** documentation on this page. | ||
|
||
There are two types of functional tests, for each of them there is a subdirectory: | ||
|
||
- [Tests designed to run on a physical compute node](./docs/compute_node_hosted/compute_node_hosted.md) | ||
|
||
|
||
- [Tests designed to run on ovc_master](./docs/ovc_master_hosted/ovc_master_hosted.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
## OpenvCloud RESTful api Tests | ||
|
||
|
||
|
||
### Continues Integration | ||
|
||
### Travis | ||
You can trigger the build from [Travis website](https://travis-ci.org/0-complexity/G8_testing) or [CI-Dashboard](https://travis-dash.gig.tech/). | ||
|
||
#### Prerequisites | ||
Travis CI build uses the environment's controller to execute the tests from it, so if your environment controller doesn't have public ip you have to: | ||
- Install zerotier [ZeroTier](zerotier.com/network) on the controller. | ||
- Create zerotier network and make the controller join it. | ||
|
||
#### Travis Parameters | ||
- ```ctrl_ipaddress```: controller's ip address (zerotier ip in case your using zerotier). | ||
- ```ctrl_user```: controller's non-root user (default: gig) | ||
- ```ctrl_user_password```: controller user ssh password. | ||
- ```environment```: environment's location code. | ||
- ```restful_ip```: the ip of the api server | ||
- ```restful_port```: the port of the api server | ||
- ```username```: [itsyou.online](https://itsyou.online) username | ||
- ```client_id```: [itsyou.online](https://itsyou.online) client id | ||
- ```client_secret```: [itsyou.online](https://itsyou.online) client secret | ||
|
||
- ```jobs```: jobs to be executed (for example ```ovc-restful``` to execute only ovc and restful jobs). | ||
- ```restful_testsuite_dir```: restful tests path. | ||
|
||
- ##### In case you are using zerotier | ||
- ```zerotier_network```: zerotier network id. | ||
- ```zerotier_token```: zerotier account token. | ||
|
||
### LOCAL EXECUTION: | ||
As long as your machine can ping the enviroment, You can execute this test suite from your local mcahine. You only need to update the `config.ini` file to be look like that | ||
``` | ||
[main] | ||
ip=be-g8-3.demo.greenitglobe.com | ||
port=443 | ||
username=gig_qa_1@itsyouonline | ||
client_id=******************************** | ||
client_secret=**************************** | ||
location=be-g8-3 | ||
``` | ||
then you can fire it using nosetests. | ||
|
||
#### Example | ||
```bash | ||
nosetests-3.4 -sv --logging-level=WARNING --rednose testcases/cloudapi/test01_disks.py --tc-file config.ini | ||
``` | ||
|
||
#### Steps to add new test case: | ||
To implement any test case in REST APIs test suite please, create a new task with the following pattern: | ||
|
||
````yaml | ||
TC name: | ||
TC ID: | ||
API: | ||
|
||
SCENARIOS: | ||
1- PERMISSION scenario. | ||
Parameterize [permitted user do correct actions > success, | ||
permitted user do incorrect actions > fail, | ||
non-permitted user do actions > fail] | ||
2- OPERATION scenarioS: | ||
You can create any number of test cases to be sure that it will cover almost all use cases of this API. | ||
|
||
NOSETEST COMMAND: | ||
nosetest command to fire these test cases. | ||
``` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[main] | ||
ip= | ||
port= | ||
username= | ||
client_id= | ||
client_secret= |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from testconfig import config | ||
from framework.utils.ovc_client import Client | ||
from framework.utils.utils import Utils | ||
|
||
ip = config['main']['ip'] | ||
port = int(config['main']['port']) | ||
client_id = config['main']['client_id'] | ||
client_secret = config['main']['client_secret'] | ||
|
||
api_client = Client(ip, port, client_id, client_secret) | ||
api_client.load_swagger() | ||
|
||
utils = Utils() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
from framework.api.cloudapi.cloudapi import Cloudapi | ||
from framework.api.system.system import System | ||
from framework.api.libcloud.libcloud import Libcloud | ||
from framework.api.cloudbroker.cloudbroker import Cloudbroker | ||
from testconfig import config | ||
import time | ||
from framework.utils.ovc_client import Client as api_client | ||
import random | ||
|
||
|
||
|
||
class Client: | ||
def __init__(self, client_id=None, client_secret=None): | ||
|
||
ip = config['main']['ip'] | ||
port = int(config['main']['port']) | ||
self.api_client = api_client(ip, port, client_id, client_secret) | ||
if client_id: | ||
self.api_client.load_swagger() | ||
self.cloudapi = Cloudapi(self.api_client) | ||
self.cloudbroker = Cloudbroker(self.api_client) | ||
self.libcloud = Libcloud(self.api_client) | ||
self.system = System(self.api_client) | ||
self._whoami = config['main']['username'] | ||
|
||
|
||
def set_auth_header(self, value): | ||
self.api_client._session.headers['Authorization'] = value | ||
|
||
def create_user(self, **kwargs): | ||
data, response = self.cloudbroker.user.create(**kwargs) | ||
|
||
if response.status_code != 200: | ||
return False | ||
|
||
return data['username'], data['password'] | ||
|
||
def create_account(self, **kwargs): | ||
data, response = self.cloudbroker.account.create(username=self._whoami, ** kwargs) | ||
|
||
if response.status_code != 200: | ||
return False | ||
|
||
account_id = int(response.text) | ||
return account_id | ||
|
||
def create_cloudspace(self, accountId, location, **kwargs): | ||
data, response = self.cloudapi.cloudspaces.create(accountId=accountId, location=location, access=self._whoami, **kwargs) | ||
|
||
if response.status_code != 200: | ||
return False | ||
|
||
cloudspace_id = int(response.text) | ||
|
||
for _ in range(20): | ||
response = self.cloudapi.cloudspaces.get(cloudspaceId=cloudspace_id) | ||
if response.json()['status'] == 'DEPLOYED': | ||
break | ||
time.sleep(5) | ||
else: | ||
return False | ||
|
||
return cloudspace_id | ||
|
||
def get_environment(self): | ||
env_location = config['main']['location'] | ||
locations = (self.api_client.cloudapi.locations.list()).json() | ||
for location in locations: | ||
if env_location == location['locationCode']: | ||
return location | ||
else: | ||
raise Exception("can't find the %s environment location in grid" % env_location) | ||
|
||
def get_random_locations(self): | ||
return random.choice(self.cloudapi.locations.list())['locationCode'] | ||
|
||
def wait_for_cloudspace_status(self,cloudspaceId,status= "DEPLOYED", timeout=300): | ||
response = self.cloudapi.cloudspaces.get(cloudspaceId=cloudspaceId) | ||
cs_status=response.json()["status"] | ||
for _ in range(timeout): | ||
if cs_status == status: | ||
break | ||
time.sleep(1) | ||
response = self.api_client.cloudapi.cloudspaces.get(cloudspaceId=cloudspaceId) | ||
cs_status=response.json()["status"] | ||
|
||
return cs_status | ||
|
||
def authenticate_user(self, username=None, password=None, **kwargs): | ||
if not username or password: | ||
username, password = self.create_user(**kwargs) | ||
|
||
api = Client() | ||
response = api.system.usermanager.authenticate(name=username, secret=password) | ||
response.raise_for_status | ||
return api, username | ||
|
||
|
||
def get_running_nodeId(self, except_nodeid=None): | ||
nodes = self.api_client.cloudbroker.computenode.list().json() | ||
for node in nodes: | ||
if int(node['referenceId']) != except_nodeid and node['status'] == 'ENABLED': | ||
return int(node['referenceId']) | ||
else: | ||
return None |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from framework.api import utils | ||
import random | ||
|
||
class Accounts: | ||
def __init__(self, api_client): | ||
self._api = api_client | ||
|
||
def list(self): | ||
return self._api.cloudapi.accounts.list() | ||
|
||
def get(self, accountId): | ||
return self._api.cloudapi.accounts.get(accountId=accountId) | ||
|
||
def create(self, access, **kwargs): | ||
data = { | ||
'name': utils.random_string(), | ||
'access': access, | ||
'maxMemoryCapacity': -1, | ||
'maxVDiskCapacity': -1, | ||
'maxCPUCapacity': -1, | ||
'maxNetworkPeerTransfer': -1, | ||
'maxNumPublicIP': -1, | ||
} | ||
data.update(** kwargs) | ||
return data, self._api.cloudapi.accounts.create(** data) | ||
|
||
def update(self, accountId, **kwargs): | ||
return self._api.cloudapi.accounts.update(accountId=accountId, **kwargs) | ||
|
||
def addUser(self, accountId, userId, accesstype='ARCXDU'): | ||
return self._api.cloudapi.accounts.addUser( | ||
accountId=accountId, | ||
userId=userId, | ||
accesstype=accesstype | ||
) | ||
|
||
def deleteUser(self, accountId, userId, recursivedelete=False): | ||
return self._api.cloudapi.accounts.deleteUser( | ||
accountId=accountId, | ||
userId=userId, | ||
recursivedelete=recursivedelete | ||
) | ||
|
||
def updateUser(self, accountId, userId, **kwargs): | ||
data = { | ||
'accountId': accountId, | ||
'userId': userId, | ||
'accesstype':random.choice(['R', 'RCX', 'ARCXDU']) | ||
} | ||
data.update(**kwargs) | ||
return data, self._api.cloudapi.accounts.updateUser(** data) | ||
|
||
def listTemplates(self, accountId): | ||
return self._api.cloudapi.accounts.listTemplates(accountId=accountId) | ||
|
||
def getConsumedCloudUnits(self, accountId): | ||
return self._api.cloudapi.accounts.getConsumedCloudUnits(accountId=accountId) | ||
|
||
def getConsumedCloudUnitsByType(self, accountId, **kwargs): | ||
data = { | ||
'accountId':accountId, | ||
'cutype': random.choice(['CU_M', 'CU_C', 'CU_D', 'CU_S', 'CU_A', 'CU_NO', 'CU_NP', 'CU_I']) | ||
} | ||
data.update(**kwargs) | ||
return self._api.cloudapi.accounts.getConsumedCloudUnitsByType(** data) | ||
|
||
def getConsumption(self, accountId, start, end): | ||
return self._api.cloudapi.accounts.getConsumption( | ||
accountId=accountId, | ||
start=start, | ||
end=end | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from framework.api.cloudapi.accounts import Accounts | ||
from framework.api.cloudapi.cloudspaces import Cloudspaces | ||
from framework.api.cloudapi.disks import Disks | ||
from framework.api.cloudapi.externalnetwork import ExternalNetwork | ||
from framework.api.cloudapi.images import Images | ||
from framework.api.cloudapi.locations import Locations | ||
from framework.api.cloudapi.machines import Machines | ||
from framework.api.cloudapi.portforwarding import Portforwarding | ||
from framework.api.cloudapi.sizes import Sizes | ||
from framework.api.cloudapi.users import Users | ||
|
||
class Cloudapi: | ||
def __init__(self, api_client): | ||
self.accounts = Accounts(api_client) | ||
self.cloudspaces = Cloudspaces(api_client) | ||
self.disks = Disks(api_client) | ||
self.externalnetwork = ExternalNetwork(api_client) | ||
self.images = Images(api_client) | ||
self.locations = Locations(api_client) | ||
self.machines = Machines(api_client) | ||
self.portforwarding = Portforwarding(api_client) | ||
self.sizes = Sizes(api_client) | ||
self.users = Users(api_client) |
Oops, something went wrong.