Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Adds doc string and validation for mirror parameter #3583

Merged
merged 1 commit into from Sep 5, 2018
Merged

Adds doc string and validation for mirror parameter #3583

merged 1 commit into from Sep 5, 2018

Conversation

vdusek
Copy link

@vdusek vdusek commented Aug 8, 2018

@pulpbot
Copy link
Member

pulpbot commented Aug 8, 2018

Can one of the admins verify this patch?

if sync_mode != 'mirror' and sync_mode != 'additive':
msg = _("'sync_mode' must either be 'mirror' or 'additive' not '{sync_mode}'")
raise ValueError(msg.format(sync_mode=sync_mode))
assert(sync_mode == 'mirror' or sync_mode == 'additive')
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see now. The value is being validated by the serializer.

Copy link
Member

Choose a reason for hiding this comment

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

I think a ValueError is more correct than an AssertionError here. Look at the description of ValueError in the standard library docs. https://docs.python.org/3/library/exceptions.html#ValueError

Copy link
Contributor

Choose a reason for hiding this comment

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

This was based on my suggestion so I'm to blame ;) The case will be more obvious if proper constants and namespacing are used:

class DeclarativeVersion:
    sync_mode_mirror = 'mirror'
    sync_mode_additive = 'additive'
    default_sync_mode = sync_mode_mirror

    def __init__(self, first_stage, repository, sync_mode=None):
         ...

        if sync_mode is None:
           sync_mode = self.default_sync_mode
       assert sync_mode in {self.sync_mode_additive, sync_mode_mirror}, 'Oops!'

IMO a declarative_version object always expects just the values/switches it was declared with therefore the assert statement is just a debugging thing.

@@ -12,7 +11,7 @@

class DeclarativeVersion:

def __init__(self, first_stage, repository, sync_mode='mirror'):
def __init__(self, first_stage, repository, sync_mode):
Copy link
Member

Choose a reason for hiding this comment

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

Do we want plugin writers to not have a default value for sync_mode?

Also if sync_mode isn't getting a default there are various docstrings that need updating.

Copy link
Author

Choose a reason for hiding this comment

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

I deleted it because it seemed to me that the default value is assigned twice. Once here and once in the file plugin. But I didn't realize that there could be plugins that might not do that. So I made the changes back. Thanks.

@codecov
Copy link

codecov bot commented Aug 9, 2018

Codecov Report

Merging #3583 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3583      +/-   ##
==========================================
+ Coverage    57.7%   57.72%   +0.01%     
==========================================
  Files          60       60              
  Lines        2523     2524       +1     
==========================================
+ Hits         1456     1457       +1     
  Misses       1067     1067
Impacted Files Coverage Δ
pulpcore/pulpcore/app/serializers/repository.py 94.52% <100%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c097a4e...b376de5. Read the comment docs.

@daviddavis
Copy link
Contributor

FYI, there's a new thread on sync modes on pulp-dev that we may want to wait on before merging this PR.

https://www.redhat.com/archives/pulp-dev/2018-August/msg00035.html

if sync_mode != 'mirror' and sync_mode != 'additive':
msg = _("'sync_mode' must either be 'mirror' or 'additive' not '{sync_mode}'")
raise ValueError(msg.format(sync_mode=sync_mode))
assert(sync_mode == 'mirror' or sync_mode == 'additive')
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should use assert here. Instead we should raise a ValueError which is already there. I think this file should be left unedited.

Copy link
Member

@bmbouter bmbouter 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 making this PR. It looks good to me, except for the edits in declarative_version.py If those are removed I can lgtm. Thanks!

@vdusek
Copy link
Author

vdusek commented Aug 10, 2018

@bmbouter You may overlooked my and @dparalen 's answers. However I made all the changes in declarative_version.py back. Thanks.

Copy link
Member

@bmbouter bmbouter left a comment

Choose a reason for hiding this comment

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

This looks good to me. Thank you @vdusek !

@dralley dralley added the 3.0 label Aug 17, 2018
@daviddavis
Copy link
Contributor

daviddavis commented Aug 23, 2018

I responded to the mailing list thread about ditching sync modes. I'm going to wait until Monday and if there's no response, let's merge this PR.

@bmbouter
Copy link
Member

@daviddavis +1

@vdusek vdusek changed the title Adds doc string and validation for sync_mode Adds doc string and validation for mirror parameter Aug 30, 2018
@daviddavis daviddavis merged commit c43834c into pulp:master Sep 5, 2018
@vdusek vdusek deleted the task_3494 branch September 11, 2018 14:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
6 participants