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

Prevent replication subscription to the same region as the current region #16446

Merged

Conversation

gtanzillo
Copy link
Member

This change prevents a user from shooting himself in the foot by creating a subscription to the same region as the server he's accessing which means creating a subscription to the same DB and region.

The side effect of doing that is, as part of subscription creation, we do a MiqRegion.destroy_region(connection, remote_region_number). In this case that will destroy the current region. This will prevent that from happening

https://bugzilla.redhat.com/show_bug.cgi?id=1507323

/cc @jrafanie

@@ -229,6 +230,12 @@ def assert_valid_schemas!
end
end

def assert_differnet_region!
Copy link
Member

Choose a reason for hiding this comment

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

typo. "differnet" should read "different"

Copy link
Member Author

Choose a reason for hiding this comment

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

😢 I'll fix that. Thanks for finding it!

Copy link
Member

Choose a reason for hiding this comment

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

Maybe he's diff'ing internet regions. :trollface:

allow(sub).to receive(:remote_region_number).and_return(remote_region1)
allow(sub).to receive(:ensure_node_created).and_return(true)

expect { sub.save! }.not_to raise_error
Copy link
Member

Choose a reason for hiding this comment

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

The code change, once spelled correctly, looks good. I don't understand all of this stubbing. Maybe that's required because of magic. Some things are just hard to test.

Copy link
Member

Choose a reason for hiding this comment

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

We can't assume pglogical is installed and the model is an ActsAsArModel so we can't really do a factory...

Some things are just hard to test.

☝️ that 😟

@gtanzillo gtanzillo force-pushed the replication-assert-different-region branch from f44389f to b01b38e Compare November 10, 2017 21:21
@gtanzillo
Copy link
Member Author

@carbonin @jrafanie Typo fixed

@@ -34,6 +34,7 @@ def self.find_by_id(to_find)

def save!
assert_valid_schemas!
assert_different_region!
Copy link
Member

Choose a reason for hiding this comment

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

Personally, I think we should check the different region first. No point in checking the schema (more expensive) if the region check fails (less expensive)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I'll change.

…gion

This change protects a user from accidentally creating a replication subscription to the same region
he is in which will result in deleting all the data from the current region.

https://bugzilla.redhat.com/show_bug.cgi?id=1507323

Fixed typo1

change 1
@gtanzillo gtanzillo force-pushed the replication-assert-different-region branch from b01b38e to 192b14e Compare November 10, 2017 22:49
@miq-bot
Copy link
Member

miq-bot commented Nov 10, 2017

Checked commits gtanzillo/manageiq@f173fdc~...192b14e with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks fine. ⭐

@carbonin carbonin added this to the Sprint 73 Ending Nov 13, 2017 milestone Nov 13, 2017
@carbonin carbonin merged commit 91d8041 into ManageIQ:master Nov 13, 2017
simaishi pushed a commit that referenced this pull request Nov 15, 2017
…-region

Prevent replication subscription to the same region as the current region
(cherry picked from commit 91d8041)

https://bugzilla.redhat.com/show_bug.cgi?id=1513508
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 244af1313265155bddc99ca7f836d7eed7a258ee
Author: Nick Carboni <[email protected]>
Date:   Mon Nov 13 09:42:49 2017 -0500

    Merge pull request #16446 from gtanzillo/replication-assert-different-region
    
    Prevent replication subscription to the same region as the current region
    (cherry picked from commit 91d8041dd47e56468dc1a217c523f20bdfbbf731)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1513508

simaishi pushed a commit that referenced this pull request Nov 20, 2017
…-region

Prevent replication subscription to the same region as the current region
(cherry picked from commit 91d8041)

https://bugzilla.redhat.com/show_bug.cgi?id=1513509
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit a3cc11a17bbd7b569d3ae92f54ded645f7465094
Author: Nick Carboni <[email protected]>
Date:   Mon Nov 13 09:42:49 2017 -0500

    Merge pull request #16446 from gtanzillo/replication-assert-different-region
    
    Prevent replication subscription to the same region as the current region
    (cherry picked from commit 91d8041dd47e56468dc1a217c523f20bdfbbf731)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1513509

d-m-u pushed a commit to d-m-u/manageiq that referenced this pull request Jun 6, 2018
…ifferent-region

Prevent replication subscription to the same region as the current region
(cherry picked from commit 91d8041)

https://bugzilla.redhat.com/show_bug.cgi?id=1513509
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.

6 participants