Skip to content

Commit fa0661a

Browse files
author
guido tijskens
committed
OLUEK-5005 oci-metadata (oci-utils) value-only flag broken
1 parent b024239 commit fa0661a

28 files changed

+1594
-143
lines changed

bin/oci-iscsi-config

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,14 @@ do
6969
break
7070
;;
7171
# end of parsing , everything getopt did not understood is after that, we do not care in our case
72-
--) shift; break ;;
73-
*) COMMAND="usage" ; break ;;
72+
--)
73+
if [ -z ${COMMAND} ]
74+
then
75+
COMMAND="usage"
76+
fi
77+
shift; break
78+
;;
79+
*) COMMAND="usage" ; break ;;
7480
esac
7581
done
7682

buildrpm/oci-utils.spec

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Name: oci-utils
2-
Version: 0.12.4
3-
Release: 4%{?dist}
2+
Version: 0.12.5
3+
Release: 2%{?dist}
44
Url: http://cloud.oracle.com/iaas
55
Summary: Oracle Cloud Infrastructure utilities
66
License: UPL
@@ -178,6 +178,15 @@ rm -rf %{buildroot}
178178
/opt/oci-utils/tests/__init__*
179179

180180
%changelog
181+
* Mon Jun 28 Guido Tijskens <[email protected]> -- 0.12.5-2
182+
- OLUEK-5005 oci-metadata (oci-utils) value-only flag broken
183+
184+
* Wed Jun 23 2021 Guido Tijskens <[email protected]> -- 0.12.5-1
185+
- modified oci-iscsi-config output in compat mode
186+
- corrected oci-iscsi-config behaviour on invalid compat syntax
187+
- some small changes
188+
- changed log and error messages
189+
181190
* Thu Jun 17 2021 Guido Tijskens <[email protected]> -- 0.12.4-4
182191
- LINUX-11136 compatibility: oci-network-config --(de)configure does not show results
183192
- LINUX-11163 compatibility: oci-network-config differences in output
@@ -237,7 +246,7 @@ rm -rf %{buildroot}
237246

238247

239248
* Tue Dec 1 2020 Guido Tijskens <[email protected]> -- 0.12.0-1
240-
- update migrate
249+
- update migrate
241250

242251
* Tue Nov 10 2020 Emmanuel Jannetti <[email protected]> --0.12.0
243252
- LINUX-9546 - oci-image-cleanup --dry-run do not print the plan directly

lib/oci_utils/cache.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ def write_cache(cache_content, cache_fname, fallback_fname=None, mode=None):
164164
if not os.path.exists(cachedir):
165165
os.makedirs(cachedir)
166166
if mode is not None:
167-
cache_fd = os.open(cache_fname, os.O_WRONLY | os.O_CREAT,
168-
mode)
167+
cache_fd = os.open(cache_fname, os.O_WRONLY | os.O_CREAT, mode)
169168
else:
170169
cache_fd = os.open(cache_fname, os.O_WRONLY | os.O_CREAT)
171170
cache_file = os.fdopen(cache_fd, 'w')
@@ -178,11 +177,9 @@ def write_cache(cache_content, cache_fname, fallback_fname=None, mode=None):
178177
if not os.path.exists(cachedir):
179178
os.makedirs(cachedir)
180179
if mode is not None:
181-
cache_fd = os.open(fallback_fname,
182-
os.O_WRONLY | os.O_CREAT, mode)
180+
cache_fd = os.open(fallback_fname, os.O_WRONLY | os.O_CREAT, mode)
183181
else:
184-
cache_fd = os.open(fallback_fname,
185-
os.O_WRONLY | os.O_CREAT)
182+
cache_fd = os.open(fallback_fname, os.O_WRONLY | os.O_CREAT)
186183
cache_file = os.fdopen(cache_fd, 'w')
187184
fname = fallback_fname
188185
except (OSError, IOError):

lib/oci_utils/impl/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@
1212
import logging.handlers
1313

1414

15-
__all__ = ['read_config', 'SUDO_CMD',
16-
'CAT_CMD', 'SH_CMD', 'CP_CMD', 'TOUCH_CMD', 'CHMOD_CMD', 'LSBLK_CMD', 'MKDIR_CMD']
15+
__all__ = ['read_config',
16+
'SUDO_CMD',
17+
'CAT_CMD',
18+
'SH_CMD',
19+
'CP_CMD',
20+
'TOUCH_CMD',
21+
'CHMOD_CMD',
22+
'LSBLK_CMD',
23+
'MKDIR_CMD']
1724

1825

1926
CAT_CMD = '/usr/bin/cat'

lib/oci_utils/impl/oci-iscsi-config-main.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ def get_args_parser():
9090
-------
9191
The commandline argparse namespace.
9292
"""
93-
parser = argparse.ArgumentParser(description='Utility for listing or configuring iSCSI devices on an OCI '
94-
'instance.')
93+
parser = argparse.ArgumentParser(description='Utility for listing or configuring iSCSI devices on an OCI instance.')
9594
subparser = parser.add_subparsers(dest='command')
9695
#
9796
# sync
@@ -428,7 +427,7 @@ def display_attached_volumes(oci_sess, iscsiadm_session, disks, output_mode, det
428427
No return value.
429428
"""
430429
#
431-
# todo: handle the None ocisession more elegantly.
430+
# todo: handle the None oci_sess more elegantly.
432431
oci_vols = list()
433432
try:
434433
if bool(oci_sess):
@@ -498,8 +497,13 @@ def display_attached_volumes(oci_sess, iscsiadm_session, disks, output_mode, det
498497
iscsi_dev_printer.printRow(_item)
499498
if output_mode == 'compat':
500499
if 'partitions' not in disks[_item['dev']]:
501-
iscsi_dev_printer.printKeyValue('File system type', disks[_item['dev']]['fstype'])
502-
iscsi_dev_printer.printKeyValue('Mountpoint', disks[_item['dev']]['mountpoint'])
500+
#
501+
# iscsi_dev_printer.printKeyValue('File system type', disks[_item['dev']]['fstype'])
502+
# iscsi_dev_printer.printKeyValue('Mountpoint', disks[_item['dev']]['mountpoint'])
503+
fstype = disks[_item['dev']]['fstype'] if bool(disks[_item['dev']]['fstype']) else 'Unknown'
504+
iscsi_dev_printer.printKeyValue('File system type', fstype)
505+
mntpoint = disks[_item['dev']]['mountpoint'] if bool(disks[_item['dev']]['mountpoint']) else 'Not mounted'
506+
iscsi_dev_printer.printKeyValue('Mountpoint', mntpoint)
503507
else:
504508
partitions = disks[device]['partitions']
505509
partitionPrinter.printHeader()
@@ -530,7 +534,7 @@ def display_detached_iscsi_device(iqn, targets, attach_failed=()):
530534
"""
531535
devicePrinter = get_row_printer_impl('table')(title="Target %s" % iqn,
532536
text_truncate=False,
533-
columns=(['Portal', 12, 'portal'], ['State', 12, 'state']))
537+
columns=(['Portal', 20, 'portal'], ['State', 65, 'state']))
534538
devicePrinter.printHeader()
535539
_item = {}
536540
for ipaddr in list(targets.keys()):
@@ -577,6 +581,7 @@ def _do_iscsiadm_attach(iqn, targets, user=None, passwd=None, iscsi_portal_ip=No
577581
if iqn in targets[ipaddr]:
578582
portal_ip = ipaddr
579583
if portal_ip is None:
584+
#
580585
# this shouldn't really happen, but just in case
581586
raise Exception("Can't find portal IP address")
582587
else:
@@ -1062,7 +1067,7 @@ def main():
10621067
if bool(oci_sess.this_instance()):
10631068
_this_instance_ocid = oci_sess.this_instance().get_ocid()
10641069
else:
1065-
_this_instance_ocid = get_instance_ocid
1070+
_this_instance_ocid = get_instance_ocid()
10661071

10671072
if 'compat' in args and args.compat is True:
10681073
# Display information as version 0.11 for compatibility reasons for few settings.
@@ -1092,7 +1097,7 @@ def main():
10921097

10931098
ocid_cache = load_cache(iscsiadm.ISCSIADM_CACHE, max_age=timedelta(minutes=2))[1]
10941099
if ocid_cache is None:
1095-
_logger.debug('updating the cache')
1100+
_logger.debug('Updating the cache')
10961101
# run ocid once, to update the cache
10971102
ocid_refresh(wait=True)
10981103
# now try to load again
@@ -1273,7 +1278,6 @@ def main():
12731278
return 1
12741279

12751280
retval = 0
1276-
12771281
for iqn in args.iqns:
12781282
_iqn_to_use = iqn
12791283
_save_chap_cred = False

lib/oci_utils/impl/oci-metadata-main.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@
7474
'publicIp',
7575
'macAddr',
7676
'subnetCidrBlock',
77-
'virtualRouterIp', ]
77+
'virtualRouterIp',
78+
'definedTags']
7879

7980
human_readable_type = {
8081
str: 'string type',
8182
dict: 'json format'}
8283

8384
oci_metadata_ignores = [
84-
'definedTags',
8585
'freeformTags',
8686
'launchMode',
8787
'ipxeScript',
@@ -436,7 +436,7 @@ def get_values(key, metadata):
436436
elif v is not None:
437437
values.append(v)
438438
return values
439-
if isinstance(metadata, dict):
439+
if not isinstance(metadata, dict):
440440
return None
441441
if key in metadata:
442442
return metadata[key]
@@ -481,7 +481,11 @@ def get_trimed_key_values(keys, metadata):
481481
if len(ks) > 1:
482482
# path key
483483
newkey_list = []
484-
_get_path_keys(metadata, ks[1:], newkey_list)
484+
try:
485+
_get_path_keys(metadata, ks[1:], newkey_list)
486+
except Exception as e:
487+
_logger.error('%s', str(e))
488+
continue
485489
for _key in newkey_list:
486490
v = _get_by_path(metadata, _key)
487491
if v:
@@ -640,6 +644,7 @@ def main():
640644
return 1
641645

642646
if args.setkeys:
647+
# set
643648
if args.keys:
644649
_logger.error("-g or --get option conflicts with -u or --update.")
645650
return 1
@@ -652,6 +657,11 @@ def main():
652657
# meta = oci_utils.oci_api.OCISession().update_instance_metadata(
653658
# instance_id=inst_id, **k_v)
654659
meta = OCISession().update_instance_metadata(instance_id=inst_id, **k_v)
660+
if meta is None:
661+
#
662+
# if meta is None, the session failed to update the metadata; the session is writing the error message;
663+
# this should change...
664+
return 1
655665
metadata = meta.filter(list(k_v.keys()))
656666
except Exception as e:
657667
_logger.error("%s", str(e), exc_info=True)
@@ -660,7 +670,7 @@ def main():
660670
# get
661671
if args.value_only:
662672
if len(args.keys) != 1:
663-
sys.stderr.write("Error: --value-only option works only with one -g or --get option.")
673+
_logger.error("Error: --value-only option works only with one -g or --get option.")
664674
return 1
665675

666676
try:

lib/oci_utils/impl/oci-network-config-main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,9 @@ def _get_subnet(_, interface):
530530
['IFACE', 15, 'IFACE'],
531531
['VLTAG', 5, 'VLTAG'],
532532
['VLAN', 11, 'VLAN'],
533-
['STATE', 5, 'STATE'], ['MAC', 17, 'MAC'], ['VNIC', 90, 'VNIC'])
533+
['STATE', 5, 'STATE'],
534+
['MAC', 17, 'MAC'],
535+
['VNIC ID', 90, 'VNIC'])
534536
printer = TablePrinter(title=_title, columns=_columns, column_separator='', text_truncate=False)
535537

536538
printer.printHeader()

lib/oci_utils/impl/ocid-main.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def request_stop(self):
153153
trigger a stop phase of the daemon
154154
set the event triggering the stop
155155
"""
156-
self.thr_logger.debug('been requested to stop')
156+
self.thr_logger.debug('Recieved a request to stop.')
157157
self.active = False
158158
self.blocking_evt.set()
159159

@@ -179,7 +179,7 @@ def run(self):
179179
if not self.active:
180180
# shutting down.
181181
self.thread_lock.release()
182-
self.thr_logger.debug('shutting down')
182+
self.thr_logger.debug('Shutting down.')
183183
break
184184
try:
185185
self.context = self.ocidfunc(self.context, self.thr_logger)
@@ -284,11 +284,9 @@ def iscsi_func(context, func_logger):
284284

285285
# Load the saved passwords
286286
chap_passwords = context['chap_pws']
287-
if context['chap_pw_ts'] == 0 or \
288-
get_timestamp(oci_utils.__chap_password_file) > context['chap_pw_ts']:
287+
if context['chap_pw_ts'] == 0 or get_timestamp(oci_utils.__chap_password_file) > context['chap_pw_ts']:
289288
# the password file has changed or was never loaded
290-
context['chap_pw_ts'], chap_passwords = \
291-
load_cache(oci_utils.__chap_password_file)
289+
context['chap_pw_ts'], chap_passwords = load_cache(oci_utils.__chap_password_file)
292290
if chap_passwords is None:
293291
chap_passwords = {}
294292
# save for the next iteration
@@ -302,10 +300,11 @@ def iscsi_func(context, func_logger):
302300
# volumes connected to this instance
303301
inst_volumes = []
304302
if context['oci_sess'] is not None:
303+
#
305304
# get a list of volumes attached to the instance
306305
instance = context['oci_sess'].this_instance()
307306
if instance is None:
308-
func_logger.debug('Cannot get current instance')
307+
func_logger.debug('Cannot get current instance.')
309308
else:
310309
volumes = instance.all_volumes()
311310
for v in volumes:
@@ -319,7 +318,9 @@ def iscsi_func(context, func_logger):
319318
else:
320319
all_iqns[v.get_portal_ip()] = [v.get_iqn()]
321320
else:
321+
#
322322
# fall back to scanning
323+
func_logger.debug('Scan for volumes.')
323324
for r in range(context['max_volumes'] + 1):
324325
ipaddr = "169.254.2.%d" % (r + 1)
325326
iqns = oci_utils.iscsiadm.discovery(ipaddr)
@@ -334,28 +335,28 @@ def iscsi_func(context, func_logger):
334335
vol['user'] = chap_passwords[iqn][0]
335336
vol['password'] = chap_passwords[iqn][1]
336337
inst_volumes.append(vol)
337-
338+
#
338339
# Load the list of volumes that were detached using oci-iscsi-config.
339340
# ocid shouldn't attach these automatically.
340341
ignore_iqns = context['ignore_iqns']
341-
if context['ignore_file_ts'] == 0 or \
342-
get_timestamp(oci_utils.__ignore_file) > context['ignore_file_ts']:
342+
if context['ignore_file_ts'] == 0 or get_timestamp(oci_utils.__ignore_file) > context['ignore_file_ts']:
343+
#
343344
# the list of detached volumes changed since last reading the file
344-
context['ignore_file_ts'], ignore_iqns = \
345-
load_cache(oci_utils.__ignore_file)
345+
context['ignore_file_ts'], ignore_iqns = load_cache(oci_utils.__ignore_file)
346346
if ignore_iqns is None:
347347
ignore_iqns = []
348+
#
348349
# save for next iteration
349350
context['ignore_iqns'] = ignore_iqns
350-
351+
#
351352
# volumes that failed to attach in an earlier iteration
352353
attach_failed = context['attach_failed']
353-
354+
#
354355
# do we need to cache files?
355356
cache_changed = False
356357
ign_changed = False
357358
chap_changed = False
358-
359+
#
359360
# check if all discovered iscsi devices are configured and attached
360361
for vol in inst_volumes:
361362
if vol['iqn'] in ignore_iqns:

0 commit comments

Comments
 (0)