Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VM's active status in comments field of switch table #801

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions zvmsdk/smtclient.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright Contributors to the Feilong Project.
# SPDX-License-Identifier: Apache-2.0

# Copyright 2017,2022 IBM Corp.
# Copyright 2017,2024 IBM Corp.
#
# 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
Expand Down Expand Up @@ -1960,7 +1960,14 @@ def _create_nic(self, userid, vdev, nic_id=None, mac_addr=None,
nic=vdev, userid=userid,
create_err=msg1, revoke_err=msg2)

self._NetDbOperator.switch_add_record(userid, vdev, port=nic_id)
# Add vm active info to comments field to be consumed by
# neutron-zvm-agent. python uses True/False but json uses true/false.
if active:
comments = "{\"active\": true}"
else:
comments = "{\"active\": false}"
LOG.info("Set comments to be %s in _create_nic." % comments)
self._NetDbOperator.switch_add_record(userid, vdev, port=nic_id, comments=comments)
msg = ('Create nic device %(vdev)s for guest %(vm)s successfully'
% {'vdev': vdev, 'vm': userid})
LOG.info(msg)
Expand Down Expand Up @@ -3462,8 +3469,17 @@ def _dedicate_OSA(self, userid, OSA_device, vdev, active=False):
def_vdev = str(hex(int(def_vdev, 16) + 1))[2:]
att_OSA_device = str(hex(int(att_OSA_device, 16) + 1))[2:]

OSA_desc = 'OSA=%s' % OSA_device
self._NetDbOperator.switch_add_record(userid, vdev, comments=OSA_desc)
# OSA_desc = 'OSA=%s' % OSA_device
# Add vm active info to comments field to be consumed by
# neutron-zvm-agent. python uses True/False but json uses true/false.
# OSA_desc isn't used currently, so comment it out. Later we can add
# it back if needed.
if active:
comments = "{\"active\": true}"
else:
comments = "{\"active\": false}"
LOG.info("Set comments to be %s in _dedicate_OSA." % comments)
self._NetDbOperator.switch_add_record(userid, vdev, comments=comments)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With line 3465 amd 3466 be commented out, the existing dedicate_OSA function would be broken.
And why line 3473 to line 3482 need be added here?

msg = ('Dedicate nic device %(vdev)s of guest %(vm)s '
'to OSA device %(osa)s successfully'
% {'vdev': vdev, 'vm': userid, 'osa': OSA_device})
Expand Down
12 changes: 7 additions & 5 deletions zvmsdk/tests/unit/test_smtclient.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright Contributors to the Feilong Project.
# SPDX-License-Identifier: Apache-2.0

# Copyright 2017,2022 IBM Corp.
# Copyright 2017,2024 IBM Corp.
#
# 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
Expand Down Expand Up @@ -2105,7 +2105,8 @@ def test_private_create_nic_active(self, power_state, request, add_record):
mac_addr='11:22:33:44:55:66',
active=True)
add_record.assert_called_once_with("fakenode", "fake_vdev",
port="fake_nic")
port="fake_nic",
comments='{"active": true}')
rd1 = ' '.join((
'SMAPI fakenode API Virtual_Network_Adapter_Create_Extended_DM',
"--operands",
Expand Down Expand Up @@ -2140,7 +2141,8 @@ def test_private_create_nic_active_retry(self, power_state, request,
mac_addr='11:22:33:44:55:66',
active=False)
add_record.assert_called_once_with("fakenode", "fake_vdev",
port="fake_nic")
port="fake_nic",
comments='{"active": false}')
cnie.assert_called_once_with(mock.ANY, 'fakenode', 'fake_vdev')
rd1 = ' '.join((
'SMAPI fakenode API Virtual_Network_Adapter_Create_Extended_DM',
Expand Down Expand Up @@ -3689,7 +3691,7 @@ def test_private_dedicate_OSA_notActive(self, request, add_rec):
"--operands -v 1001 -r f001")
request.assert_any_call('SMAPI userid API Image_Device_Dedicate_DM '
"--operands -v 1002 -r f002")
add_rec.assert_called_once_with('userid', '1000', comments='OSA=f000')
add_rec.assert_called_once_with('userid', '1000', comments='{"active": false}')

@mock.patch.object(smtclient.SMTClient, '_request')
def test_private_dedicate_OSA_notActive_Fail_Input(self, request):
Expand Down Expand Up @@ -3759,7 +3761,7 @@ def test_private_dedicate_OSA_Active(self, power_state, request, add_rec):
"--operands -v 1001 -r f001")
request.assert_any_call('SMAPI userid API Image_Device_Dedicate '
"--operands -v 1002 -r f002")
add_rec.assert_called_once_with('userid', '1000', comments='OSA=f000')
add_rec.assert_called_once_with('userid', '1000', comments='{"active": true}')

@mock.patch.object(smtclient.SMTClient, '_request')
@mock.patch.object(smtclient.SMTClient, 'get_power_state')
Expand Down
Loading