Skip to content

Commit

Permalink
Add API test node create
Browse files Browse the repository at this point in the history
Change-Id: I47883db3d767dd8cfc8096e9237264bc9600afc6
  • Loading branch information
sturivny committed Nov 25, 2016
1 parent b85a4e4 commit 73952b7
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 8 deletions.
12 changes: 12 additions & 0 deletions api_tests/baremetal/test_api_node.py
Expand Up @@ -28,3 +28,15 @@ def test_nodes_get(api_ironic_steps_v1):
#. Get ironic nodes
"""
api_ironic_steps_v1.get_ironic_nodes()


@pytest.mark.idempotent_id('21d65216-78b1-4206-bd8b-faad76c079dc')
@pytest.mark.usefixtures('ironic_node_steps')
def test_node_create(api_ironic_steps_v1):
"""**Scenario:** Verify that ironic node can be created via API.
**Steps:**
#. Create ironic node
"""
api_ironic_steps_v1.create_ironic_nodes()
16 changes: 16 additions & 0 deletions stepler/baremetal/api_clients/base.py
Expand Up @@ -18,6 +18,7 @@
# limitations under the License.

from stepler import base
from stepler import config


class IronicApiClient(base.BaseApiClient):
Expand All @@ -26,3 +27,18 @@ class IronicApiClient(base.BaseApiClient):
@property
def _endpoint(self):
return self._session.get_endpoint(service_type='baremetal').rstrip('/')

@property
def _auth_headers(self):
"""Get auth headers.
Returns:
dict: authentication headers.
"""
auth_headers = super(IronicApiClient, self)._auth_headers
auth_headers.update({
'User-Agent': 'python-ironicclient',
'X-OpenStack-Ironic-API-Version':
config.CURRENT_IRONIC_MICRO_VERSION
})
return auth_headers
29 changes: 29 additions & 0 deletions stepler/baremetal/api_clients/node_v1.py
Expand Up @@ -50,4 +50,33 @@ def node_get(self, node_ident):
response = self._get('/v1/nodes/{}'.format(node_ident))
response.raise_for_status()

return [Resource(self, response.json())]

def node_create(self, driver, name=None, driver_info=None):
"""Create node via API call.
Args:
name(str): node name
driver(str): node driver
driver_info(json): node driver info
Returns:
object: ironic node
"""
data = {"name": name,
"driver": driver,
"driver_info": driver_info}

response = self._post('/v1/nodes/', data=data)
response.raise_for_status()

return Resource(self, response.json())

def node_delete(self, node_ident):
"""Delete node via API call.
Args:
node_ident (str): the UUID or Name of the node.
"""
response = self._delete('/v1/nodes/{}'.format(node_ident))
response.raise_for_status()
6 changes: 3 additions & 3 deletions stepler/baremetal/fixtures/clients.py
Expand Up @@ -42,7 +42,7 @@ def get_api_ironic_client(get_session):
def _get_api_ironic_client(version, is_api):
if version == '1':
if is_api:
return api_clients.NodeApiClientV1(session=get_session())
return api_clients.IronicApiClientV1(session=get_session())
else:
return client_v1.get_client(session=get_session())

Expand All @@ -56,7 +56,7 @@ def ironic_client_v1(get_api_ironic_client):
"""Function fixture to get ironic client v1.
Args:
get_ironic_client (function): function to get ironic client
get_api_ironic_client (function): function to get ironic client
Returns:
ironicclient.get_client: instantiated ironic client
Expand All @@ -69,7 +69,7 @@ def api_ironic_client_v1(get_api_ironic_client):
"""Function fixture to get API ironic client v1.
Args:
get_ironic_client (function): function to get ironic client
get_api_ironic_client (function): function to get ironic client
Returns:
api_clients.ApiClientV1: instantiated API ironic client v1
Expand Down
2 changes: 1 addition & 1 deletion stepler/baremetal/steps/node.py
Expand Up @@ -21,10 +21,10 @@
from ironicclient import exceptions

from stepler.base import BaseSteps
from stepler.third_party.matchers import expect_that
from stepler.third_party import steps_checker
from stepler.third_party import utils
from stepler.third_party import waiter
from stepler.third_party.waiter import expect_that

__all__ = [
'IronicNodeSteps'
Expand Down
9 changes: 5 additions & 4 deletions stepler/base.py
Expand Up @@ -263,8 +263,10 @@ def _auth_headers(self):
dict: authentication headers.
"""
# TODO(schipiga): may be need to use native API

return { # catch only token to avoid side effects
'X-Auth-Token': self._session.get_auth_headers()['X-Auth-Token']}
'X-Auth-Token': self._session.get_auth_headers()['X-Auth-Token'],
}

@property
def _endpoint(self):
Expand Down Expand Up @@ -294,15 +296,14 @@ def _put(self, url, headers=None, data=None, **kwgs):

return requests.put(url, headers=headers, data=data, **kwgs)

def _post(self, url, headers=None, data=None, json=None, **kwgs):
def _post(self, url, headers=None, data=None, **kwgs):
"""POST request to API."""
headers = headers or {}
headers.update(self._auth_headers)

url = self._endpoint + url

return requests.post(
url, headers=headers, data=data, json=json, **kwgs)
return requests.post(url, headers=headers, json=data, **kwgs)

def _patch(self, url, headers=None, data=None, **kwgs):
"""PATCH request to API."""
Expand Down
1 change: 1 addition & 0 deletions stepler/config.py
Expand Up @@ -90,6 +90,7 @@
CURRENT_GLANCE_VERSION = '2'
CURRENT_CINDER_VERSION = '2'
CURRENT_IRONIC_VERSION = '1'
CURRENT_IRONIC_MICRO_VERSION = '1.9'

# SERVICES
CINDER_VOLUME = 'cinder-volume'
Expand Down

0 comments on commit 73952b7

Please sign in to comment.