diff options
author | Zhijiang Hu <hu.zhijiang@zte.com.cn> | 2017-09-06 07:59:35 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-09-06 07:59:35 +0000 |
commit | a1cac571306e246206368cd5ed324c3f2203e1cb (patch) | |
tree | 8e863f10f1589a94d4ccb175768d205da2562579 | |
parent | 21086d1bce255c464f57bf6bc183894d7d9bbfba (diff) | |
parent | 95aec0a10931ecc61981dba49c93c5bea8d48960 (diff) |
Merge "Eliminate hard coding about ipmi info"
-rw-r--r-- | deploy/config/schemas.py | 17 | ||||
-rw-r--r-- | deploy/environment.py | 18 | ||||
-rw-r--r-- | tests/data/lab_conf/deploy_baremetal.yml | 38 | ||||
-rw-r--r-- | tests/unit/config/test_schemas.py | 5 |
4 files changed, 59 insertions, 19 deletions
diff --git a/deploy/config/schemas.py b/deploy/config/schemas.py index 3096d017..0e013eb9 100644 --- a/deploy/config/schemas.py +++ b/deploy/config/schemas.py @@ -7,6 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import copy from jsonschema import Draft4Validator, FormatChecker import sys import yaml @@ -73,6 +74,10 @@ deploy_schema = { 'required': ['hosts', 'daisy_passwd', 'daisy_gateway'] } +deploy_schema_bm = copy.deepcopy(deploy_schema) +deploy_schema_bm['properties']['hosts']['items']['required'] = \ + ['roles', 'ipmi_ip', 'ipmi_user', 'ipmi_pass'] + def _validate(data, schema): v = Draft4Validator(schema, format_checker=FormatChecker()) @@ -80,15 +85,11 @@ def _validate(data, schema): return errors -def item_validate(data, schema_type): - if schema_type not in schema_mapping: - return str('Schema Type %s does not exist' % schema_type) - else: - return _validate(data, schema_mapping.get(schema_type)) - - def deploy_schema_validate(data): - return _validate(data, deploy_schema) + if data.get('adapter', 'libvirt') == 'ipmi': + return _validate(data, deploy_schema_bm) + else: + return _validate(data, deploy_schema) def _main(): diff --git a/deploy/environment.py b/deploy/environment.py index dd9e0142..5371e6ca 100644 --- a/deploy/environment.py +++ b/deploy/environment.py @@ -147,17 +147,15 @@ class BareMetalEnvironment(DaisyEnvironmentBase): disks=[self.daisy_server_info['image']]) def reboot_nodes(self, boot_dev=None): - # TODO: add ipmi info into deploy.yml, or read from PDF - address = 106 for node in self.deploy_struct['hosts']: - node['ipmiIp'] = '192.168.1.' + str(address) - address += 1 - if address > 111: - err_exit('the ipmi address exceeds the range 106~110') - node['ipmiUser'] = 'zteroot' - node['ipmiPass'] = 'superuser' - ipmi_reboot_node(node['ipmiIp'], node['ipmiUser'], - node['ipmiPass'], boot_source=boot_dev) + if 'ipmi_ip' not in node \ + or 'ipmi_user' not in node \ + or 'ipmi_pass' not in node: + err_exit('Missing ipmi information') + ipmi_reboot_node(node['ipmi_ip'], + node['ipmi_user'], + node['ipmi_pass'], + boot_source=boot_dev) def deploy(self, deploy_file, net_file): self.server.prepare_cluster(deploy_file, net_file) diff --git a/tests/data/lab_conf/deploy_baremetal.yml b/tests/data/lab_conf/deploy_baremetal.yml new file mode 100644 index 00000000..8f9b2644 --- /dev/null +++ b/tests/data/lab_conf/deploy_baremetal.yml @@ -0,0 +1,38 @@ +adapter: 'ipmi' +hosts: +- name: 'controller01' + roles: + - 'CONTROLLER_LB' + ipmi_ip: '192.168.1.11' + ipmi_user: 'testuser' + ipmi_pass: 'testpass' +- name: 'controller02' + roles: + - 'CONTROLLER_LB' + ipmi_ip: '192.168.1.12' + ipmi_user: 'testuser' + ipmi_pass: 'testpass' +- name: 'controller03' + roles: + - 'CONTROLLER_LB' + ipmi_ip: '192.168.1.13' + ipmi_user: 'testuser' + ipmi_pass: 'testpass' +- name: 'computer01' + roles: + - 'COMPUTER' + ipmi_ip: '192.168.1.14' + ipmi_user: 'testuser' + ipmi_pass: 'testpass' +- name: 'computer02' + roles: + - 'COMPUTER' + ipmi_ip: '192.168.1.15' + ipmi_user: 'testuser' + ipmi_pass: 'testpass' +disks: + daisy: 50 +daisy_passwd: 'r00tme' +daisy_ip: '10.20.0.2' +daisy_gateway: '10.20.0.1' +ceph_disk_name: '/dev/sdb' diff --git a/tests/unit/config/test_schemas.py b/tests/unit/config/test_schemas.py index 04705fda..7c7dab28 100644 --- a/tests/unit/config/test_schemas.py +++ b/tests/unit/config/test_schemas.py @@ -23,7 +23,8 @@ def conf_file_dir(data_root): @pytest.mark.parametrize('deploy_file_name', [ ('deploy_virtual1.yml'), - ('deploy_virtual_error.yml')]) + ('deploy_virtual_error.yml'), + ('deploy_baremetal.yml')]) def test_deploy_schema_validate(conf_file_dir, deploy_file_name): data = yaml.safe_load(open(os.path.join(conf_file_dir, deploy_file_name), 'r')) errors = deploy_schema_validate(data) @@ -31,3 +32,5 @@ def test_deploy_schema_validate(conf_file_dir, deploy_file_name): assert errors == [] elif deploy_file_name == 'deploy_virtual_error.yml': assert errors != [] + elif deploy_file_name == 'deploy_baremetal.yml': + assert errors == [] |