-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ IF-5903 add bto baremetals api * ✨ IF-5903 add bto baremetals api * ✨ IF-5903 add bto baremetals api Co-authored-by: oizaki.atsushi <atsushi.oizaki@ntt.com>
- Loading branch information
Showing
6 changed files
with
325 additions
and
6 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
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,64 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from ecl.baremetal import baremetal_service | ||
from ecl import resource2 | ||
|
||
|
||
class Chassis(resource2.Resource): | ||
"""Chassis Resource""" | ||
|
||
resource_key = 'chassis' | ||
resources_key = 'chassis' | ||
base_path = '/chassis' | ||
service = baremetal_service.BaremetalService() | ||
|
||
# Capabilities | ||
allow_get = True | ||
allow_list = True | ||
|
||
# Properties | ||
#: The ID for the chassis, which is a unique integer value. | ||
id = resource2.Body('id') | ||
#: The name of availability zone where chassis exists. | ||
availability_zone = resource2.Body('availability_zone') | ||
#: The name of flavor of chassis. | ||
flavor_name = resource2.Body('flavor_name') | ||
#: The object of summarized hardware spec. That has cpus, disks and rams. | ||
hardware_summary = resource2.Body('hardware_summary', type=dict) | ||
#: The status of chassis. | ||
status = resource2.Body('status') | ||
#: The ID of server attached to chassis. If no server is attached to chassis, the value is null. | ||
server_id = resource2.Body('server_id') | ||
#: The name of server attached to chassis. If no server is attached to chassis, the value is null. | ||
server_name = resource2.Body('server_name') | ||
#: The minimum contract period of your chassis. | ||
contract_year = resource2.Body('contract_year', type=int) | ||
#: The date that you start to use the chassis. | ||
start_time = resource2.Body('start_time') | ||
|
||
# Properties (for Detail) | ||
#: The spec of all cpus installed in chassis. | ||
cpus = resource2.Body('cpus', type=list) | ||
#: The spec of all disks installed in chassis. | ||
disks = resource2.Body('disks', type=list) | ||
#: The spec of all rams installed in chassis. | ||
rams = resource2.Body('rams', type=list) | ||
|
||
|
||
class ChassisDetail(Chassis): | ||
"""ChassisDetail Resource""" | ||
|
||
base_path = '/chassis/detail' | ||
|
||
# Capabilities | ||
allow_get = False |
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
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,83 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import six | ||
|
||
from ecl.tests.functional import base | ||
|
||
|
||
class TestChassis(base.BaseFunctionalTest): | ||
|
||
def test_chassis(self): | ||
chassis_list = list(self.conn.baremetal.chassis(details=False)) | ||
self.assertGreater(len(chassis_list), 0) | ||
|
||
for chassis in chassis_list: | ||
print(chassis) | ||
self.assertIsInstance(chassis.id, six.string_types) | ||
self.assertIsInstance(chassis.availability_zone, six.string_types) | ||
self.assertIsInstance(chassis.flavor_name, six.string_types) | ||
self.assertIsInstance(chassis.hardware_summary, dict) | ||
self.assertIsInstance(chassis.status, six.string_types) | ||
self.assertIsInstance(chassis.server_id, | ||
(six.string_types, type(None))) | ||
self.assertIsInstance(chassis.server_name, | ||
(six.string_types, type(None))) | ||
self.assertIsInstance(chassis.contract_year, int) | ||
self.assertIsInstance(chassis.start_time, six.string_types) | ||
|
||
def test_chassis_detail(self): | ||
chassis_list = list(self.conn.baremetal.chassis(details=True)) | ||
self.assertGreater(len(chassis_list), 0) | ||
|
||
for chassis in chassis_list: | ||
print(chassis) | ||
self.assertIsInstance(chassis.id, six.string_types) | ||
self.assertIsInstance(chassis.availability_zone, six.string_types) | ||
self.assertIsInstance(chassis.flavor_name, six.string_types) | ||
self.assertIsInstance(chassis.hardware_summary, dict) | ||
self.assertIsInstance(chassis.status, six.string_types) | ||
self.assertIsInstance(chassis.server_id, | ||
(six.string_types, type(None))) | ||
self.assertIsInstance(chassis.server_name, | ||
(six.string_types, type(None))) | ||
self.assertIsInstance(chassis.contract_year, int) | ||
self.assertIsInstance(chassis.start_time, six.string_types) | ||
|
||
self.assertIsInstance(chassis.cpus, list) | ||
self.assertIsInstance(chassis.disks, list) | ||
self.assertIsInstance(chassis.rams, list) | ||
|
||
def test_get_chassis(self): | ||
# ChassisIDはMock Serverに合わせて変更する | ||
chassis_id = '31e7a0c4-f49e-19e6-2192-c9f9cc6f5a74' | ||
|
||
chassis = self.conn.baremetal.get_chassis(chassis_id) | ||
print(chassis) | ||
# Mock Serverを使用するとランダムなUUIDが返却されるのでパスパラメータを一致しない | ||
# self.assertEqual(chassis.id, chassis_id) | ||
|
||
self.assertIsInstance(chassis.availability_zone, six.string_types) | ||
self.assertIsInstance(chassis.flavor_name, six.string_types) | ||
self.assertIsInstance(chassis.hardware_summary, dict) | ||
self.assertIsInstance(chassis.status, six.string_types) | ||
self.assertIsInstance(chassis.server_id, | ||
(six.string_types, type(None))) | ||
self.assertIsInstance(chassis.server_name, | ||
(six.string_types, type(None))) | ||
self.assertIsInstance(chassis.contract_year, int) | ||
self.assertIsInstance(chassis.start_time, six.string_types) | ||
|
||
self.assertIsInstance(chassis.cpus, list) | ||
self.assertIsInstance(chassis.disks, list) | ||
self.assertIsInstance(chassis.rams, list) | ||
|
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
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,99 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import testtools | ||
|
||
from ecl.baremetal.v2 import chassis | ||
|
||
IDENTIFIER = 'IDENTIFIER' | ||
CHASSIS_EXAMPLE = { | ||
'id': IDENTIFIER, | ||
'availability_zone': '2', | ||
'flavor_name': '3', | ||
'hardware_summary': {'4': 4}, | ||
'status': '5', | ||
'server_id': '6', | ||
'server_name': '7', | ||
'contract_year': 8, | ||
'start_time': '9', | ||
} | ||
|
||
CHASSIS_DETAIL_EXAMPLE = { | ||
'id': IDENTIFIER, | ||
'availability_zone': '2', | ||
'flavor_name': '3', | ||
'hardware_summary': {'4': 4}, | ||
'status': '5', | ||
'server_id': '6', | ||
'server_name': '7', | ||
'contract_year': 8, | ||
'start_time': '9', | ||
'cpus': [{'10': 10},], | ||
'disks': [{'11': 11},], | ||
'rams': [{'12': 12},], | ||
} | ||
from unittest.mock import patch | ||
|
||
class TestChassis(testtools.TestCase): | ||
|
||
def test_basic(self): | ||
sot = chassis.Chassis() | ||
self.assertEqual('chassis', sot.resource_key) | ||
self.assertEqual('chassis', sot.resources_key) | ||
self.assertEqual('/chassis', sot.base_path) | ||
self.assertEqual('baremetal-server', sot.service.service_type) | ||
self.assertTrue(sot.allow_get) | ||
self.assertTrue(sot.allow_list) | ||
self.assertFalse(sot.allow_create) | ||
self.assertFalse(sot.allow_delete) | ||
self.assertFalse(sot.allow_update) | ||
self.assertFalse(sot.allow_head) | ||
|
||
def test_make_basic(self): | ||
sot = chassis.Chassis(**CHASSIS_EXAMPLE) | ||
self.assertEqual(CHASSIS_EXAMPLE['id'], sot.id) | ||
self.assertEqual(CHASSIS_EXAMPLE['availability_zone'], sot.availability_zone) | ||
self.assertEqual(CHASSIS_EXAMPLE['flavor_name'], sot.flavor_name) | ||
self.assertEqual(CHASSIS_EXAMPLE['hardware_summary'], sot.hardware_summary) | ||
self.assertEqual(CHASSIS_EXAMPLE['status'], sot.status) | ||
self.assertEqual(CHASSIS_EXAMPLE['server_id'], sot.server_id) | ||
self.assertEqual(CHASSIS_EXAMPLE['server_name'], sot.server_name) | ||
self.assertEqual(CHASSIS_EXAMPLE['contract_year'], sot.contract_year) | ||
self.assertEqual(CHASSIS_EXAMPLE['start_time'], sot.start_time) | ||
|
||
def test_detail(self): | ||
sot = chassis.ChassisDetail() | ||
self.assertEqual('chassis', sot.resource_key) | ||
self.assertEqual('chassis', sot.resources_key) | ||
self.assertEqual('/chassis/detail', sot.base_path) | ||
self.assertEqual('baremetal-server', sot.service.service_type) | ||
self.assertFalse(sot.allow_get) | ||
self.assertTrue(sot.allow_list) | ||
self.assertFalse(sot.allow_create) | ||
self.assertFalse(sot.allow_delete) | ||
self.assertFalse(sot.allow_update) | ||
self.assertFalse(sot.allow_head) | ||
|
||
def test_make_detail(self): | ||
sot = chassis.ChassisDetail(**CHASSIS_DETAIL_EXAMPLE) | ||
self.assertEqual(CHASSIS_DETAIL_EXAMPLE['id'], sot.id) | ||
self.assertEqual(CHASSIS_DETAIL_EXAMPLE['availability_zone'], sot.availability_zone) | ||
self.assertEqual(CHASSIS_DETAIL_EXAMPLE['flavor_name'], sot.flavor_name) | ||
self.assertEqual(CHASSIS_DETAIL_EXAMPLE['hardware_summary'], sot.hardware_summary) | ||
self.assertEqual(CHASSIS_DETAIL_EXAMPLE['status'], sot.status) | ||
self.assertEqual(CHASSIS_DETAIL_EXAMPLE['server_id'], sot.server_id) | ||
self.assertEqual(CHASSIS_DETAIL_EXAMPLE['server_name'], sot.server_name) | ||
self.assertEqual(CHASSIS_DETAIL_EXAMPLE['contract_year'], sot.contract_year) | ||
self.assertEqual(CHASSIS_DETAIL_EXAMPLE['start_time'], sot.start_time) | ||
self.assertEqual(CHASSIS_DETAIL_EXAMPLE['cpus'], sot.cpus) | ||
self.assertEqual(CHASSIS_DETAIL_EXAMPLE['disks'], sot.disks) | ||
self.assertEqual(CHASSIS_DETAIL_EXAMPLE['rams'], sot.rams) |