Sitelet https://web.archive.org/web/20220402023213im_/https://github.com/apache/cloudstack/pull/3058
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

CLOUDSTACK-3049: update dynamic role for an account #3058

Merged
merged 1 commit into from Jan 25, 2019

Conversation

bwsw
Copy link
Contributor

@bwsw bwsw commented Nov 26, 2018 •

Description

Existing 'updateAccount' API call now can update role as well as account name and network domain. During the implementation 'newname' attribute was marked as optional, previously in the API was annotated as required, which is not a right behavior.

New Dockerfile was added Dockerfile.smokedev which is convenient if you develop smoke tests.

Helper script was added to deploy datacenter and run tests from the same docker image which guarantees a predictable environment.

docker run -v ~/dev/tmp:/tmp \
      -v ~/IdeaProjects/cloudstack/test/integration/smoke:/root/test/integration/smoke \
      -it \
      --name simulator -p 8080:8080 -p8096:8096 simulator:4.12

# second console 
docker exec -it simulator bash
# deploy datacenter
bash /root/docker_run_tests.sh advanced smoke
# follow the instructions

Implements #3049

Types of changes

  • Enhancement (improves an existing feature and functionality)

Screenshots (if appropriate):

How Has This Been Tested?

  • The code was tested with cloudmonkey
  • Smoketest for Marvin was implemented

@bwsw bwsw force-pushed the 3049-update-dynamic-role branch 3 times, most recently from 40b1d13 to f2cac02 Compare Nov 26, 2018
@rohityadavcloud
Copy link
Member

@rohityadavcloud rohityadavcloud commented Nov 27, 2018

Can you instead implement a cleaner approach, say create a new API?

Copy link
Member

@rafaelweingartner rafaelweingartner left a comment

Thanks @bwsw. I have only one comment regarding a set of nested IFs that can be improved.

Differently from @rhtyd I do not think we need another API method. From my perspective, the role is part of the account. Therefore, when updating the account I should/"would want to" be able to change the role as well.

if (duplicateAcccount != null && duplicateAcccount.getId() != account.getId()) {
throw new InvalidParameterValueException(
"There already exists an account with the name:" + newAccountName + " in the domain:" + domainId + " with existing account id:" + duplicateAcccount.getId());
if(newAccountName != null) {
Copy link
Member

@rafaelweingartner rafaelweingartner Nov 27, 2018

Choose a reason for hiding this comment

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

You can use StringUtils.isEmpty here. Then, you do not need all of these netsting

Copy link
Contributor Author

@bwsw bwsw Nov 27, 2018

Choose a reason for hiding this comment

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

@rafaelweingartner
Hm, I don't think so or don't get the idea. I would like to distinguish three situations:

  1. newAccountName is not specified
  2. newAccountName is specified but empty string -> exception 1
  3. newAccountName is specified and not empty string -> action or exception

So, don't get how StringUtils.isEmpty() helps.

Copy link
Member

@rafaelweingartner rafaelweingartner Nov 27, 2018

Choose a reason for hiding this comment

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

What I am saying is the following:

Instead of (the current code):

 if(newAccountName != null) {

            if (newAccountName.isEmpty()) {
                throw new InvalidParameterValueException("The new account name for account '" + account.getUuid() + "' " +
                        "within domain '" + domainId + "'  is empty string. Account will be not renamed.");
            }

            // check if the new proposed account name is absent in the domain
            Account existingAccount = _accountDao.findActiveAccount(newAccountName, domainId);
            if (existingAccount != null && existingAccount.getId() != account.getId()) {
                throw new InvalidParameterValueException("The account with the proposed name '" +
                        newAccountName + "' exists in the domain '" +
                        domainId + "' with existing account id '" + existingAccount.getId() + "'");
            }

            acctForUpdate.setAccountName(newAccountName);
        }

You can do the following:

 if(StringUtils.isBlank(newAccountName)) {
         throw new InvalidParameterValueException("The new account name for account '" + account.getUuid() + "' " +
                        "within domain '" + domainId + "'  is an empty string. Account will be not renamed.");

  }

	// check if the new proposed account name is absent in the domain
	Account existingAccount = _accountDao.findActiveAccount(newAccountName, domainId);
	if (existingAccount != null && existingAccount.getId() != account.getId()) {
		throw new InvalidParameterValueException("The account with the proposed name '" +
				newAccountName + "' exists in the domain '" +
				domainId + "' with existing account id '" + existingAccount.getId() + "'");
	}

  acctForUpdate.setAccountName(newAccountName);

By doing that you remove one nesting level.

Did you understand what I am saying now?

Copy link
Contributor Author

@bwsw bwsw Nov 27, 2018

Choose a reason for hiding this comment

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

@rafaelweingartner But how it will behave if newAccountName is null which is normal if API is not intending to change that. It is a normal case and whole code block must be skipped.

Copy link
Member

@rafaelweingartner rafaelweingartner Nov 27, 2018

Choose a reason for hiding this comment

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

good catch. I was not paying attention to this detail. Then, I would simply do newAccountName != null && StringUtils.isBlank(newAccountName).

That is only a suggestion. You can leave the code as is if you think it is better this way.

Copy link
Contributor Author

@bwsw bwsw Nov 27, 2018

Choose a reason for hiding this comment

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

@rafaelweingartner ok. I'll leave as is.

@borisstoyanov
Copy link
Contributor

@borisstoyanov borisstoyanov commented Nov 27, 2018

@blueorangutan package

@blueorangutan
Copy link

@blueorangutan blueorangutan commented Nov 27, 2018

@borisstoyanov a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan
Copy link

@blueorangutan blueorangutan commented Nov 27, 2018

Packaging result: ✔centos6 ✔centos7 ✔debian. JID-2464

@borisstoyanov
Copy link
Contributor

@borisstoyanov borisstoyanov commented Nov 27, 2018

@blueorangutan
Copy link

@blueorangutan blueorangutan commented Nov 27, 2018

@borisstoyanov a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@bwsw
Copy link
Contributor Author

@bwsw bwsw commented Nov 27, 2018

Can you instead implement a cleaner approach, say create a new API?

@rhtyd I considered both alternatives. My arguments for the current implementation:

  1. it adds smoke tests for updateAccount and as you can see before the implementation there wasn't testing for the method at all.
  2. updateAccount method was strangely implemented, e.g. one has to pass newname mandatory, this enhancement fixes the behavior as well.
  3. It's natural, I agree with Rafael, otherwise, it's true to implement every update<Entity><Attribute> separately and it will be hell without scoping.

What do you think?

@rohityadavcloud
Copy link
Member

@rohityadavcloud rohityadavcloud commented Nov 27, 2018

It's end of my day, let me get back to you soon. In short, my hesitation stems from the fact that the operation in question has some security and privileges implications. As a general rule such an update param/operation must be privileged and checked. It's better to have this as separate api. Take example of other apis which change ownership, transfer relationships etc all cases which could too be solved by an update api as well.

@rohityadavcloud
Copy link
Member

@rohityadavcloud rohityadavcloud commented Nov 27, 2018

Another note that there is a translation implication of accounttype that maybe implemented as well. Due to backward compatibility, we support both account type and roleid for the create api for example.

@bwsw
Copy link
Contributor Author

@bwsw bwsw commented Nov 27, 2018

It's end of my day, let me get back to you soon. In short, my hesitation stems from the fact that the operation in question has some security and privileges implications. As a general rule such an update param/operation must be privileged and checked. It's better to have this as separate api. Take example of other apis which change ownership, transfer relationships etc all cases which could too be solved by an update api as well.

@rhtyd Well, if we decide that only global admin (not domain admin) can change that, then you are right, it's better to implement as a separate API call.

@bwsw bwsw force-pushed the 3049-update-dynamic-role branch from 6dcdb20 to de843db Compare Nov 27, 2018
@rafaelweingartner
Copy link
Member

@rafaelweingartner rafaelweingartner commented Nov 27, 2018

@bwsw if you use the authorize field in the @Parameter definition for the new role (the role being changed/updated) I think that then you can achieve what @rhtyd wanted. I mean, then we would be able to allow the use of such parameter only for admins or root admins.

@blueorangutan
Copy link

@blueorangutan blueorangutan commented Nov 27, 2018

Trillian test result (tid-3220)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 20717 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr3058-t3220-kvm-centos7.zip
Intermittent failure detected: /marvin/tests/smoke/test_multipleips_per_nic.py
Intermittent failure detected: /marvin/tests/smoke/test_vpc_redundant.py
Smoke tests completed. 68 look OK, 2 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File
test_nic_secondaryip_add_remove Error 22.60 test_multipleips_per_nic.py
test_04_rvpc_network_garbage_collector_nics Failure 441.49 test_vpc_redundant.py
test_05_rvpc_multi_tiers Failure 282.94 test_vpc_redundant.py
test_05_rvpc_multi_tiers Error 306.08 test_vpc_redundant.py

@bwsw
Copy link
Contributor Author

@bwsw bwsw commented Nov 27, 2018

@rhtyd @rafaelweingartner
Well, currently the implementation allows changing the account details only for admin or domain admin. Admin can set any role while domain admin can set only DomainAdmin, ResourceAdmin, User types.
I suppose that basically, it's what users need.

Please, approve the basic design and then I write the tests for security assurance. Just don't want to spend the time if the design initially doesn't fit.

@GabrielBrascher GabrielBrascher added this to the 4.12.0.0 milestone Dec 6, 2018
@rafaelweingartner
Copy link
Member

@rafaelweingartner rafaelweingartner commented Jan 9, 2019

@blueorangutan package

@blueorangutan
Copy link

@blueorangutan blueorangutan commented Jan 9, 2019

@rafaelweingartner a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan
Copy link

@blueorangutan blueorangutan commented Jan 9, 2019

Packaging result: ✖centos6 ✔centos7 ✔debian. JID-2526

@GabrielBrascher
Copy link
Member

@GabrielBrascher GabrielBrascher commented Jan 9, 2019

@blueorangutan
Copy link

@blueorangutan blueorangutan commented Jan 9, 2019

@GabrielBrascher a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan
Copy link

@blueorangutan blueorangutan commented Jan 10, 2019

Trillian test result (tid-3303)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 22789 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr3058-t3303-kvm-centos7.zip
Intermittent failure detected: /marvin/tests/smoke/test_multipleips_per_nic.py
Intermittent failure detected: /marvin/tests/smoke/test_vpc_redundant.py
Smoke tests completed. 68 look OK, 2 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File
test_nic_secondaryip_add_remove Error 33.79 test_multipleips_per_nic.py
test_04_rvpc_network_garbage_collector_nics Failure 495.45 test_vpc_redundant.py

"There already exists an account with the name:" + newAccountName + " in the domain:" + domainId + " with existing account id:" + duplicateAcccount.getId());
if(newAccountName != null) {

if (newAccountName.isEmpty()) {
Copy link
Contributor

@dhlaluku dhlaluku Jan 15, 2019

Choose a reason for hiding this comment

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

@bwsw could you please add a comment here to specify that you are checking that the user did not pass an empty string for an optional parameter. Otherwise I think it is a bit confusing why you check if a not null string is empty. At least I found it confusing until I saw the conversation between you and @rafaelweingartner. Overall LGTM

Copy link
Member

@GabrielBrascher GabrielBrascher Jan 24, 2019

Choose a reason for hiding this comment

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

@bwsw can you please address @dhlaluku comment? Thanks!

Copy link
Contributor

@dhlaluku dhlaluku left a comment

LGTM

@bwsw
Copy link
Contributor Author

@bwsw bwsw commented Jan 24, 2019

@GabrielBrascher Hi, Gabriel, you have mentioned this PR as a problematic. It has got two LGTM. Please, comment on what do you want me to improve to be merged?

@GabrielBrascher
Copy link
Member

@GabrielBrascher GabrielBrascher commented Jan 24, 2019

@bwsw this one is looking good indeed, I must have dropped this PR on the wrong list.

Just to mention, independently of the "list" that the issue/PR was placed I will be getting in touch and help reviewing, testing, and pinging contributors/reviewers.

Thanks for pinging me, keep the good work 👍

@GabrielBrascher
Copy link
Member

@GabrielBrascher GabrielBrascher commented Jan 24, 2019

@blueorangutan package

@blueorangutan
Copy link

@blueorangutan blueorangutan commented Jan 24, 2019

@GabrielBrascher a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan
Copy link

@blueorangutan blueorangutan commented Jan 24, 2019

Packaging result: ✔centos6 ✔centos7 ✔debian. JID-2563

@bwsw
Copy link
Contributor Author

@bwsw bwsw commented Jan 24, 2019

@GabrielBrascher Sounds great.

@GabrielBrascher
Copy link
Member

@GabrielBrascher GabrielBrascher commented Jan 24, 2019

@blueorangutan
Copy link

@blueorangutan blueorangutan commented Jan 24, 2019

@GabrielBrascher a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan
Copy link

@blueorangutan blueorangutan commented Jan 24, 2019

Trillian test result (tid-3344)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 20504 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr3058-t3344-kvm-centos7.zip
Smoke tests completed. 70 look OK, 0 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File

@GabrielBrascher
Copy link
Member

@GabrielBrascher GabrielBrascher commented Jan 25, 2019

Thanks for the work guys, this one looks ready to merge (LGTMs + tests are good).

@GabrielBrascher GabrielBrascher merged commit d68712e into apache:master Jan 25, 2019
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants