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

Updates to mark-for-op support for hours #2323

Merged
merged 9 commits into from May 5, 2018

Conversation

nimbusscale
Copy link
Contributor

  • Makes updates discussed in actions: mark-for-op, hours as well as days #2006
  • Changes hour support so that it includes the minutes as well. Prior the minutes were replaced with 0 leading to unexpected behavior.
  • Added mark-for-op hours support for asgs
  • Added test_asg_marked_for_op_hours unit test


default_template = (
'AutoScaleGroup does not meet org policy: {op}@{action_date}')

def process(self, asgs):
self.tz = zoneinfo.gettz(
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should move to a validate method, ideally we shouldn't even be in policy execution on a config validation error.

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'm not sure if I quite follow, but I think I understand what you are saying. I think you are saying that by the time we get to process we should almost certain it's going to work, so there should be a validate method to check before we process. I see some examples elsewhere in the code base.

So I think you are asking that:

        if not self.tz:
            raise FilterValidationError(
                "Invalid timezone specified %s" % self.tz)

be moved into a validate method?

I copied this logic from the previous PR that made the updated in tags.py seen here https://github.com/capitalone/cloud-custodian/blob/3a24d34bf59386f0377e984248e77aa28ccef7c5/c7n/tags.py#L608. But looking at the code again, I'm not sure if this if not self.tz is even needed as we set a value right above and default to utc.

Maybe you are asking for:

        self.tz = zoneinfo.gettz(
            Time.TZ_ALIASES.get(self.data.get('tz', 'utc')))

to be moved out of the process method and then the if not self.tz moved to a validate method?

Any clarification here would be helpful and I'll apply the same to the code in tags.py.

}, session_factory=session_factory)
resources = policy.run()
self.assertEqual(len(resources), 1)
self.assertEqual(resources[0]['AutoScalingGroupName'], 'marked')
Copy link
Collaborator

Choose a reason for hiding this comment

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

ideally this should also construct an asg client and verify the value of the tag, else we're not testing the behavior/implementation just that it ran without errors.

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've added a test test_asg_mark_for_op_hours that mirrors what I saw for for the ec2 changes, hopefully this is what you are looking for.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yup. thanks

# maintains default value of days being 4 if nothing is provided
days = 4
action_date = (n + timedelta(days=days, hours=hours))
return action_date.strftime('%Y/%m/%d %H%M %Z')
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think we should only retain hours/minutes if hours is set.

@kapilt
Copy link
Collaborator

kapilt commented May 3, 2018

Thanks for the pr and getting to the cla, looks good, some minors on the review.

Copy link
Collaborator

@kapilt kapilt left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

@nimbusscale
Copy link
Contributor Author

Thanks, is there anything else I need to do to get this merged?

@kapilt kapilt merged commit a5cf21c into cloud-custodian:master May 5, 2018
@kapilt
Copy link
Collaborator

kapilt commented May 5, 2018

all good, thanks

lamyanba pushed a commit to lamyanba/cloud-custodian that referenced this pull request Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants