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

Openstack Swift DB Backups #17967

Merged
merged 11 commits into from
Oct 11, 2018
Merged

Openstack Swift DB Backups #17967

merged 11 commits into from
Oct 11, 2018

Conversation

jerryk55
Copy link
Member

In support of the RFE described in BZ https://bugzilla.redhat.com/show_bug.cgi?id=1615488.

Add a new FileDepot subclass for Swift.
Since we need to pass info in to the Mount Session (in gems-pending) regarding the Openstack
connection, utilize the URI with Query Parameters to do so.

@carbonin @NickLaMuro @roliveri please review.

Links

@jerryk55
Copy link
Member Author

jerryk55 commented Sep 11, 2018 via email

@jerryk55
Copy link
Member Author

@carbonin any chance of a final review and merge on this? Thanks!

Copy link
Member

@NickLaMuro NickLaMuro left a comment

Choose a reason for hiding this comment

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

Just something I noticed that is in regards to what I am working on. (Update: Derp... this is wrong... resolving)

lib/evm_database_ops.rb Show resolved Hide resolved
@NickLaMuro NickLaMuro dismissed their stale review September 17, 2018 21:01

I was clearly confused... ignore me

Copy link
Member

@carbonin carbonin left a comment

Choose a reason for hiding this comment

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

@agrare can you weigh in on how we should be writing out Open[s|S]tack?

'smb' => 'Samba',
'nfs' => 'Network File System',
's3' => 'AWS S3',
'swift' => 'Openstack Swift'
Copy link
Member

Choose a reason for hiding this comment

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

Should this be OpenStack? Not sure how exact we need to be with branding here (I'm not sure if this is displayed to the user).

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok cool. I have to change this in here and in the UI code as well. Thanks for pointing it out.

end

def verify_credentials(auth_type = nil, options = {})
auth_type ||= 'default'
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't we just make 'default' the .. well .. default value for the parameter in the method definition? Why have the parameter default be nil then set a value if it's nil.

Copy link
Member Author

Choose a reason for hiding this comment

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

Absolutely.

'smb' => 'Samba',
'nfs' => 'Network File System',
's3' => 'Amazon Web Services',
'swift' => 'Openstack Swift'
Copy link
Member

Choose a reason for hiding this comment

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

Same question here about Openstack vs OpenStack

uri.query = [uri.query, "region=#{openstack_region}"].compact.join('&') if openstack_region.present?
uri.query = [uri.query, "api_version=#{keystone_api_version}"].compact.join('&') if keystone_api_version.present?
uri.query = [uri.query, "domain_id=#{v3_domain_ident}"].compact.join('&') if v3_domain_ident.present?
uri.query = [uri.query, "security_protocol=#{security_protocol}"].compact.join('&') if security_protocol.present?
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 we could simplify this a bit by building a list of query elements outside of the uri.query string object. Like this:

query_elements = []
query_elements << "region=#{openstack_region}"              if openstack_region.present?
query_elements << "api_version=#{keystone_api_version}"     if keystone_api_version.present?
query_elements << "domain_id=#{v3_domain_ident}"]           if v3_domain_ident.present?
query_elements << "security_protocol=#{security_protocol}"] if security_protocol.present?
uri.query = query_elements.join('&').presence

Also we can drop the .present? calls if these will only ever be nil or usable.

Copy link
Member Author

Choose a reason for hiding this comment

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

If its nil then we'll end up with query strings like "region=&api_version=&domain_id=", won't we?

Copy link
Member

Choose a reason for hiding this comment

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

Nope, I'm pretty sure my version works as I'm only adding the key=value if the value is present, then joining only when the array is fully assembled.

Also, I'm not sure what "it" you're referencing here, but we should probably have a test for this method either way. I would suggest writing some tests that cover nil values and then we can refactor with confidence.

Copy link
Member Author

Choose a reason for hiding this comment

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

@carbonin I'm referring to your question about dropping the ".present?" calls if these will be nil or usable. if they're nil, and there is no .present? call, then the wrong thing will happen. Your code works correctly as written.

Copy link
Member

Choose a reason for hiding this comment

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

if they're nil, and there is no .present? call, then the wrong thing will happen.

No, nil is falsey.

This won't print anything:

foo = nil
puts "this won't print" if foo

What present? and presence do is move empty strings (and also other empty objects like arrays, hashes, etc) to also be false or nil respectively. So when I saw you using present? I assumed that these could possibly be empty strings, but that seemed strange, which is why I asked.

Copy link
Member Author

Choose a reason for hiding this comment

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

Doh! Obviously my physical exhaustion is affecting my mental capacity. Of course what you're saying is true. I think I need more coffee...

locale/en.yml Outdated
@@ -730,6 +730,7 @@ en:
FileDepotFtpAnonymous: Anonymous FTP
FileDepotNfs: NFS
FileDepotS3: AWS S3
FileDepotSwift: Openstack Swift
Copy link
Member

Choose a reason for hiding this comment

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

Same as the others.

Copy link
Member

@carbonin carbonin left a comment

Choose a reason for hiding this comment

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

We should add specs here. At least for FileDepotSwift#merged_uri, but ideally for more.


def merged_uri(uri, api_port)
port = api_port.presence || 5000
uri = URI.parse("#{URI(uri).scheme}://#{URI(uri).host}:#{port}#{URI(uri).path}")
Copy link
Member

Choose a reason for hiding this comment

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

Ah this was supposed to be part of the review, but this is rather complicated and I don't understand what it is accomplishing. Specs would help.

Copy link
Member Author

Choose a reason for hiding this comment

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

Putting the port in the URI.

Copy link
Member

Choose a reason for hiding this comment

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

Since we had the same kind of things here:

ManageIQ/manageiq-appliance_console#66 (review)

Can we switch to just assigning port to the uri object as well? (instead of the quadruple URI.parse)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes! I thought that was in this PR someplace - I forgot where we'd done it. Thanks!

@jerryk55
Copy link
Member Author

jerryk55 commented Oct 9, 2018

@NickLaMuro @carbonin I've fixed the issue with credential verification. I see that there was a request for a spec in one case but other than this should be ready to go. The UI PR is ready to go and waiting on this one. I have gems-pending code from Nick L to push out and we should be ready at least with the Backup side of the equation if I can get buy-in from everyone. Let me look at a spec here.

Copy link
Member

@NickLaMuro NickLaMuro left a comment

Choose a reason for hiding this comment

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

I think this looks good to me, but I am a bit fuzzy on the workflow of the FileDepot code, so I might have missed something.

The comments I left are minor, so they don't need to hold up the merge.

app/models/file_depot_swift.rb Show resolved Hide resolved
@@ -0,0 +1,69 @@
class FileDepotSwift < FileDepot
attr_accessor :swift
Copy link
Member

Choose a reason for hiding this comment

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

Is this used?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not that I'm aware of. Removing.

@jerryk55
Copy link
Member Author

jerryk55 commented Oct 9, 2018

@carbonin tests added. ready to rock and roll?

Copy link
Member

@carbonin carbonin left a comment

Choose a reason for hiding this comment

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

Nearly there, just some minor cleanup type stuff.

connect(options.merge(:auth_type => auth_type))
rescue Excon::Errors::Unauthorized => err
msg = "Access to Swift host #{host} failed due to a bad username or password."
logger.error("Access to Swift host #{host} failed due to a bad username or password. #{err}")
Copy link
Member

Choose a reason for hiding this comment

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

Same

app/models/file_depot_swift.rb Show resolved Hide resolved
app/models/miq_schedule.rb Show resolved Hide resolved
spec/models/file_depot_swift_spec.rb Outdated Show resolved Hide resolved
@jerryk55
Copy link
Member Author

@carbonin All comments addressed and pushed.

expect(FileDepotSwift.uri_prefix).to eq "swift"
end

context "valid merged uri" do
Copy link
Member

Choose a reason for hiding this comment

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

This should really be the name of the method under test in this block. Also I prefer describe for blocks which are testing a particular method and use context for blocks which define shared setup.

So this would be the convention we normally would use here:

describe "#merged_uri" do

In support of the RFE described in BZ https://bugzilla.redhat.com/show_bug.cgi?id=1615488.

Add a new FileDepot subclass for Swift.
Since we need to pass info in to the Mount Session (in gems-pending) regarding the Openstack
connection, utilize the URI with Query Parameters to do so.
Several changes based on PR review comments -
1) Change "Openstack Swift" to "OpenStack Swift"
2) Fix default argument handling
3) Refactor Query String processing.
Fix credentials verification.  Cleanup extra log messages.
Add some spec tests for the class including the merged_uri method.
Fixed one test so that it doesn't use the default port for the URI.
Cleaned up some msg logging to be more efficient.
The merged_uri method was working incorrectly - coded to let the
spec tests succeed but the validation of the Swift connection to fail.
Some formatting changes based on review comments.
@jerryk55
Copy link
Member Author

@carbonin spec changes made as requested.

@carbonin carbonin merged commit 520f007 into ManageIQ:master Oct 11, 2018
@carbonin carbonin self-assigned this Oct 11, 2018
@carbonin carbonin added this to the Sprint 97 Ending Oct 22, 2018 milestone Oct 11, 2018
@carbonin
Copy link
Member

@jerryk55 We're still targeting hammer for this right?

@jerryk55
Copy link
Member Author

Yup. Assuming that the restore side can be finished by then. Which we are relying on @NickLaMuro to do the bulk of that... UI, Core, and Schema are merged. I'm working through comments on the backup side of the gems-pending PR, and there is still an outstanding appliance_console PR.

simaishi pushed a commit that referenced this pull request Oct 12, 2018
@simaishi
Copy link
Contributor

Hammer backport details:

$ git log -1
commit e5e724a18e9887514fc0753b7d122991c9f81ec4
Author: Nick Carboni <ncarboni@redhat.com>
Date:   Thu Oct 11 11:48:16 2018 -0400

    Merge pull request #17967 from jerryk55/swift_db_backups
    
    Openstack Swift DB Backups
    
    (cherry picked from commit 520f0077af3b3373bab9b692f50224575cfc332b)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1615488

@miq-bot
Copy link
Member

miq-bot commented Oct 12, 2018

Checked commits jerryk55/manageiq@fc21e30~...c25ac99 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
8 files checked, 4 offenses detected

app/models/file_depot_swift.rb

spec/models/file_depot_swift_spec.rb

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