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

Snapshot notify #1554

Merged
merged 9 commits into from
Nov 4, 2021
Merged

Conversation

hariha74
Copy link
Contributor

Function change to enable or disable notification for snapshot notification

@hariha74
Copy link
Contributor Author


BlockGetAndSetOutput
FileGetAndSet

@allmightyspiff
Copy link
Member

API features in this request will be public when FBLOCK-4191 is complete.

Copy link
Member

@allmightyspiff allmightyspiff left a comment

Choose a reason for hiding this comment

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

Thanks for the pull request, just a few changes needed.

  1. Fix the style checks
  2. CLI commands here should both use the Click flag option so users can just do slcli file set-notify-status --enable
  3. Command storage API calls go in the storage manager
  4. No need for the **kwargs in the managers.
  5. Add unit tests for these functions


if (enabled == ''):
click.echo(
'Snapshots space usage threshold warning flag setting is null. Set to default value enable. For volume %s'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'Snapshots space usage threshold warning flag setting is null. Set to default value enable. For volume %s'
'Snapshots space usage threshold warning flag setting is null. Use `slcli block snapshot-set-notification %s --enable` to enable'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

Comment on lines 12 to 16
@click.option(
'--notification_flag',
help=
'Enable / disable sending sending notifications for snapshots space usage threshold warning [True|False]',
required=True)
Copy link
Member

Choose a reason for hiding this comment

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

Click has a flag option, use that here, and set the default to Enable.

Suggested change
@click.option(
'--notification_flag',
help=
'Enable / disable sending sending notifications for snapshots space usage threshold warning [True|False]',
required=True)
@click.option(
'--enable/disable', required=True, default=True,
help='Enable / disable sending sending notifications for snapshots space usage threshold warning',
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@environment.pass_env
def cli(env, volume_id, notification_flag):
"""Enables/Disables snapshot space usage threshold warning for a given volume"""
if (notification_flag not in ['True', 'False']):
Copy link
Member

Choose a reason for hiding this comment

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

This wont be needed when you switch to the click flag

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 12 to 16
@click.option(
'--notification_flag',
help=
'Enable / disable sending sending notifications for snapshots space usage threshold warning [True|False]',
required=True)
Copy link
Member

Choose a reason for hiding this comment

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

Click has a flag option, use that here, and set the default to Enable.

Suggested change
@click.option(
'--notification_flag',
help=
'Enable / disable sending sending notifications for snapshots space usage threshold warning [True|False]',
required=True)
@click.option(
'--enable/disable', required=True, default=True,
help='Enable / disable sending sending notifications for snapshots space usage threshold warning',
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -102,6 +102,25 @@ def get_block_volume_snapshot_list(self, volume_id, **kwargs):
"""
return self.get_volume_snapshot_list(volume_id, **kwargs)

def set_block_volume_snapshot_notification(self, volume_id, notification_flag, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

  1. Add this to the storage manager, not the block/file managers since the code is exactly the same. The block/file managers inherit from the storage manager, so you shouldn't even need to edit your cli code.
  2. Don't pass **kwargs into the API, and likely don't even need to accept them in this function unless these methods take in objectMasks or objectFilters, which I'm guessing they wont

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -129,7 +129,24 @@ def get_file_volume_snapshot_list(self, volume_id, **kwargs):
:return: Returns a list of snapshots for the specified volume.
"""
return self.get_volume_snapshot_list(volume_id, **kwargs)
def set_file_volume_snapshot_notification(self, volume_id, notification_flag, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Same comments as the block manager

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -112,6 +112,15 @@ def get_volume_snapshot_list(self, volume_id, **kwargs):
kwargs['mask'] = ','.join(items)

return self.client.call('Network_Storage', 'getSnapshots', id=volume_id, **kwargs)
def set_volume_snapshot_notification(self, volume_id, notification_flag, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

remove the **kwargs as its not really needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@FernandoOjeda FernandoOjeda left a comment

Choose a reason for hiding this comment

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

Looks good, just a comment.

:param volume_id: ID of volume.
:param kwargs:
:param notification-flag: Enable/Disable flag for snapshot warning notification.
:return: Enables/Disables snapshot space usage threshold warning for a given volume.
Copy link
Contributor

@FernandoOjeda FernandoOjeda Oct 26, 2021

Choose a reason for hiding this comment

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

It would be good if you specify what type of data this method is returning too:
e.g.
bool or an object for example SoftLayer_Network_Storage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did not get your recommendation. The return type is a string from an SLCLI perspective. Its a message


:param volume_id: ID of volume.
:param kwargs:
:return: Enabled/Disabled snapshot space usage threshold warning for a given volume.
Copy link
Contributor

Choose a reason for hiding this comment

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

The same that above, about specifying what type of data this method is returning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did not get your recommendation. The return type is a string from an SLCLI perspective. Its a message

Copy link
Member

@allmightyspiff allmightyspiff left a comment

Choose a reason for hiding this comment

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

I'm a little concerned that it looks like this API is returning and requiring the strings "True" and "False" instead of actual boolean values, if that is the case then the API needs to be updated to fix that.

In any case, the python code should just be dealing with the boolean values, and not the strings. Hopefully that makes sense.

Also, please mark the comments as "resolved" when you resolve them, that helps. And make sure you remove the undeeded code in the file/block managers that you moved to the storage manager since those are no longer needed. Thanks.

Comment on lines 21 to 24
if enable:
enabled = 'True'
else:
enabled = 'False'
Copy link
Member

Choose a reason for hiding this comment

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

This wont work. Just pass the boolean value into the manager/api, otherwise the SL API will interpret it as a string, which PHP will always treat as true. Just pass enable into the manager function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am in agreement with you. However, this is sort of limitation of code flow between python and PHP. I tried sending the flag but its not properly getting received at the REST end. If required i can demonstrate over a webex.
The current code is test verified over an SLCLI and screenshots are uploaded.

Suggested change
if enable:
enabled = 'True'
else:
enabled = 'False'
if enable:
enabled = 'True'
else:
enabled = 'False'

Comment on lines 21 to 25
if enable:
enabled = 'True'
else:
enabled = 'False'

Copy link
Member

Choose a reason for hiding this comment

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

This wont work. Just pass the boolean value into the manager/api, otherwise the SL API will interpret it as a string, which PHP will always treat as true. Just pass enable into the manager function.

SoftLayer/CLI/file/snapshot/get_notify_status.py Outdated Show resolved Hide resolved
SoftLayer/CLI/block/snapshot/get_notify_status.py Outdated Show resolved Hide resolved
@allmightyspiff
Copy link
Member

allmightyspiff commented Oct 28, 2021

Testing Results:

  1. get-status on a volume that hasn't had the status set
$ ./slcli -vvv  block  snapshot-get-notification-status 235854228

Calling: SoftLayer_Network_Storage::getSnapshotNotificationStatus(id=235854228, mask='', filter='None', args=(), limit=None, offset=None))

https://api.softlayer.com:443 "GET /rest/v3.1/SoftLayer_Network_Storage/235854228/getSnapshotNotificationStatus.json HTTP/1.1" 200 4

Returned Data:
None

Snapshots space usage threshold warning flag setting is disabled for volume 235854228
  1. Set the status to enabled
$ ./slcli -vvv  block  snapshot-set-notification 235854228 --enable
Calling: SoftLayer_Network_Storage::setSnapshotNotification(id=235854228, mask='', filter='None', args=('True',), limit=None, offset=None))

Returned Data:
None

curl -u $SL_USER:$SL_APIKEY -X POST -H "Accept: */*" -H "Accept-Encoding: gzip, deflate, compress" -d '{"parameters": ["True"]}' 'https://api.softlayer.com/rest/v3.1/SoftLayer_Network_Storage/235854228/setSnapshotNotification.json'
  1. Get an enabled status
$ ./slcli -vvv  block  snapshot-get-notification-status 235854228
Calling: SoftLayer_Network_Storage::getSnapshotNotificationStatus(id=235854228, mask='', filter='None', args=(), limit=None, offset=None))

Returned Data:
True

Snapshots space usage threshold warning flag setting is enabled for volume 235854228
  1. Set status to disabled
./slcli -vvv  block  snapshot-set-notification 235854228 --disable
Calling: SoftLayer_Network_Storage::setSnapshotNotification(id=235854228, mask='', filter='None', args=('False',), limit=None, offset=None))

Returned Data:
None

curl -u $SL_USER:$SL_APIKEY -X POST -H "Accept: */*" -H "Accept-Encoding: gzip, deflate, compress" -d '{"parameters": ["False"]}' 'https://api.softlayer.com/rest/v3.1/SoftLayer_Network_Storage/235854228/setSnapshotNotification.json'

  1. Get disabled status
$ ./slcli -vvv  block  snapshot-get-notification-status 235854228
Calling: SoftLayer_Network_Storage::getSnapshotNotificationStatus(id=235854228, mask='', filter='None', args=(), limit=None, offset=None))

Returned Data:
False

Snapshots space usage threshold warning flag setting is disabled for volume 235854228
  1. Set the status to something that isn't the strings "True"/"False"
$ slcli  -vvv call-api  SoftLayer_Network_Storage setSnapshotNotification --id=235854228 LitterallyAnyhting
Calling: SoftLayer_Network_Storage::setSnapshotNotification(id=235854228, mask='', filter='{}', args=('LitterallyAnyhting',), limit=None, offset=None))

Returned Data:
None

curl -u $SL_USER:$SL_APIKEY -X POST -H "Accept: */*" -H "Accept-Encoding: gzip, deflate, compress" -d '{"parameters": ["LitterallyAnyhting"]}' 'https://api.softlayer.com/rest/v3.1/SoftLayer_Network_Storage/235854228/setSnapshotNotification.json'

$ ./slcli -vvv  block  snapshot-get-notification-status 235854228
Calling: SoftLayer_Network_Storage::getSnapshotNotificationStatus(id=235854228, mask='', filter='None', args=(), limit=None, offset=None))

Returned Data:
LitterallyAnyhting
Snapshots space usage threshold warning flag setting is disabled for volume 235854228

@hariha74 For this API method, I really think you need to make SoftLayer_Network_Storage/setSnapshotNotification accept only a boolean value, and SoftLayer_Network_Storage/getSnapshotNotificationStatus return only a boolean value. Otherwise between the various ways a user can call this API, you are going to have all sorts of strings in this status table and its going to be a mess.

You should also make sure the documentation for these methods looks correct.
https://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage/setSnapshotNotification/ needs to not have <<EOT as the description. and the description for https://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage/getSnapshotNotificationStatus/ is incorrect, looks copied directly from another method instead.

When those API methods are updated to return only a boolean value, I think updating this CLI code to work with that should be pretty straight forward and make everything a lot easier. Let me know if you have any questions.

@hariha74
Copy link
Contributor Author

I am in agreement as i said earlier. Essentially, the way boolean is interpreted in a PHP ( as True ) is different from a boolean is interpreted in python ( true ). I would recommend to have a webex once to have a deep dive discussion. I am scheduling it for Tuesday ( Monday being a holiday in India ). Thanks again for all your help in analyzing the code and providing your valuable comments.

Copy link
Member

@allmightyspiff allmightyspiff left a comment

Choose a reason for hiding this comment

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

Need to fix the code style errors first, but otherwise looks fine. You can check the analysis with tox -e analysis in your local softlayer-python directory.

@allmightyspiff allmightyspiff merged commit 76c4203 into softlayer:master Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants