Fix: First boot from floppy, not CD-ROM
[ta/remote-installer.git] / src / remoteinstaller / installer / bmc_management / hw17.py
1 # Copyright 2019 Nokia
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from .bmctools import BMC, BMCException
16 import logging
17 import time
18
19 class HW17(BMC):
20     def __init__(self, host, user, passwd, priv_level='ADMINISTRATOR', log_path=None):
21         super(HW17, self).__init__(host, user, passwd, priv_level, log_path)
22
23     def attach_virtual_cd(self, nfs_host, nfs_mount, boot_iso_filename):
24         for _ in range(2):
25             self._setup_bmc_nfs_service(nfs_host, nfs_mount, boot_iso_filename)
26             success = self._wait_for_bmc_nfs_service(90, 'mounted')
27             if success:
28                 return True
29             else:
30                 logging.debug('BMC NFS server did not start yet')
31                 self.reset()
32
33         raise BMCException('NFS service setup failed')
34
35     def _detach_virtual_media(self):
36         logging.debug('Detach virtual media')
37
38         comp_code = self._run_ipmitool_raw_command('0x3c 0x00')
39         if comp_code[0] == '80':
40             raise BMCException('BMC NFS service reset failed, cannot get configuration')
41         elif comp_code[0] == '81':
42             raise BMCException('BMC NFS service reset failed, cannot set configuration')
43         else:
44             BMCException('BMC NFS service reset failed (rc={})'.format(comp_code))
45
46     def _set_boot_from_virtual_media(self):
47         logging.debug('Set boot from cd (%s), and boot after that', self._host)
48         self._run_ipmitool_command('chassis bootdev floppy options=persistent')
49
50     def _get_bmc_nfs_service_status(self):
51         logging.debug('Get BMC NFS service status')
52
53         status_code = self._run_ipmitool_raw_command('0x3c 0x03')
54         if status_code[0] == '00':
55             status = 'mounted'
56         elif status_code[0] == '64':
57             status = 'mounting'
58         elif status_code[0] == 'ff':
59             status = 'dismounted'
60         elif status_code[0] == '20':
61             status = 'nfserror'
62         else:
63             raise BMCException('Could not get BMC NFS service status (rc={})'.format(status_code))
64
65         logging.debug('Returned status: %s', status)
66         return status
67
68     def _set_bmc_nfs_configuration(self, nfs_host, mount_path, image_name):
69         logging.debug('Set BMC NFS configuration')
70
71         nfs_host_hex = self._convert_to_hex(nfs_host)
72         mount_path_hex = self._convert_to_hex(mount_path)
73         image_name_hex = self._convert_to_hex(image_name)
74
75         logging.debug('Set the IP address of the BMC NFS service (%s)', self._host)
76         comp_code = self._run_ipmitool_raw_command('0x3c 0x01 0x00 {} 0x00'.format(nfs_host_hex))
77         if comp_code[0] != '':
78             raise BMCException('Failed to set BMC NFS service IP address (rc={})'.format(comp_code))
79
80         logging.debug('Set the path of the BMC NFS service (%s)', mount_path)
81         comp_code = self._run_ipmitool_raw_command('0x3c 0x01 0x01 {} 0x00'.format(mount_path_hex))
82         if comp_code[0] != '':
83             raise BMCException('Failed to set BMC NFS service path (rc={})'.format(comp_code))
84
85         logging.debug('Set the ISO image name of the BMC NFS service (%s)', image_name)
86         comp_code = self._run_ipmitool_raw_command('0x3c 0x01 0x02 {} 0x00'.format(image_name_hex))
87         if comp_code[0] != '':
88             raise BMCException('Failed to set BMC NFS service iso image name (rc={})'.format(comp_code))
89
90     def _setup_bmc_nfs_service(self, nfs_host, mount_path, image_name):
91         logging.debug('Setup BMC NFS service')
92
93         self._detach_virtual_media()
94         self._set_bmc_nfs_configuration(nfs_host, mount_path, image_name)
95
96         logging.debug('Start the BMC NFS service')
97         comp_code = self._run_ipmitool_raw_command('0x3c 0x02 0x01')
98         if comp_code[0] != '':
99             raise BMCException('Failed to start the BMC NFS service (rc={})'.format(comp_code))
100