Skip to content

Add tags to the identity v3 project#1882

Merged
jtopjian merged 5 commits intogophercloud:masterfrom
randomswdev:add-project-tags
Mar 6, 2020
Merged

Add tags to the identity v3 project#1882
jtopjian merged 5 commits intogophercloud:masterfrom
randomswdev:add-project-tags

Conversation

@randomswdev
Copy link
Copy Markdown
Contributor

For #1687

Links to the line numbers/files in the OpenStack source code that support the
code in this PR:
https://github.com/openstack/keystone/blob/fe39838f712880c336e18eadf320e7c9e2007448/keystone/api/projects.py#L111
https://github.com/openstack/keystone/blob/fe39838f712880c336e18eadf320e7c9e2007448/keystone/api/projects.py#L233
https://github.com/openstack/keystone/blob/fe39838f712880c336e18eadf320e7c9e2007448/keystone/api/projects.py#L265
https://github.com/openstack/keystone/blob/fe39838f712880c336e18eadf320e7c9e2007448/keystone/api/projects.py#L490

This pull request adds supports for assocaiting tags to projects using the idenetity v3 APIs. The tags are optional thua llowing backward compatibility with OpenStack versions older than Queens: it is enough to not specify tags when creating or updating a project.

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 3, 2020

Coverage Status

Coverage increased (+0.01%) to 77.125% when pulling dee948a on randomswdev:add-project-tags into cf66cbf on gophercloud:master.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Mar 3, 2020

Build failed.

@randomswdev
Copy link
Copy Markdown
Contributor Author

I looked at the logs of the gophercloud-acceptance-test but I was unable to understand why the test failed. Is there anybody who can help me in locating the failure reasons?

@jtopjian
Copy link
Copy Markdown
Contributor

jtopjian commented Mar 3, 2020

@randomswdev It's an issue at OpenLab - you can safely ignore

@kayrus
Copy link
Copy Markdown
Contributor

kayrus commented Mar 3, 2020

@randomswdev could you please implement tags support for ListOpts as well?

@randomswdev
Copy link
Copy Markdown
Contributor Author

randomswdev commented Mar 3, 2020

@randomswdev could you please implement tags support for ListOpts as well?

Looking at the rest api documentation, my understanding is that the project list api does not support filtering on tags. @kayrus Can you double check and let me know? In case I’ll add the tags to the ListOpts tomorrow morning.

@kayrus
Copy link
Copy Markdown
Contributor

kayrus commented Mar 3, 2020

@jtopjian
Copy link
Copy Markdown
Contributor

jtopjian commented Mar 3, 2020

I'm not a stickler for full API support. If it's convenient for you, feel free to add tag filtering support for listing. Otherwise, it can always be done in another PR.

@randomswdev
Copy link
Copy Markdown
Contributor Author

@randomswdev I think this is it if I'm not mistaken https://github.com/openstack/keystone/blob/fe39838f712880c336e18eadf320e7c9e2007448/keystone/api/projects.py#L130

Added the suggested filters. Sorry for missing them, but the REST API documentation didn't mention them.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Mar 4, 2020

Build failed.

@jtopjian
Copy link
Copy Markdown
Contributor

jtopjian commented Mar 4, 2020

Sorry for missing them

There's no apology needed. Like I said, it wasn't a requirement to have these included.

Thank you for your work on this. Let me know if this is ready for a code review.

@randomswdev
Copy link
Copy Markdown
Contributor Author

Thank you for your work on this. Let me know if this is ready for a code review.

I think it is ready for review.

Copy link
Copy Markdown
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

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

@randomswdev Thank you for working on this.

There are two minor nits with the test fixtures. The larger comment has to do with the ability to remove all tags from a project.

In addition, we'll need to have the doc.go file updated to show examples of how to use these additions. And if possible, can you add some acceptance tests?

Bernardo Pastorelli added 2 commits March 4, 2020 22:20
@randomswdev
Copy link
Copy Markdown
Contributor Author

In addition, we'll need to have the doc.go file updated to show examples of how to use these additions. And if possible, can you add some acceptance tests?

In my last two commits I added an acceptance test that executes few tag related operations and I updated doc.go

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Mar 5, 2020

Build failed.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Mar 5, 2020

Build failed.

@jtopjian
Copy link
Copy Markdown
Contributor

jtopjian commented Mar 5, 2020

@randomswdev Thanks!

I had to make the following changes for the acceptance tests to work:

--- a/acceptance/openstack/identity/v3/projects_test.go
+++ b/acceptance/openstack/identity/v3/projects_test.go
@@ -224,7 +224,7 @@ func TestProjectsTags(t *testing.T) {
        for _, project := range allProjects {
                tools.PrintResource(t, project)

-               if project.Name == "admin" {
+               if project.Name == projectMain.Name {
                        found = true
                }
        }
@@ -259,7 +259,7 @@ func TestProjectsTags(t *testing.T) {
        for _, project := range allProjects {
                tools.PrintResource(t, project)

-               if project.Name == "admin" {
+               if project.Name == projectMain.Name {
                        found = true
                }
        }
@@ -277,7 +277,16 @@ func TestProjectsTags(t *testing.T) {
        allProjects, err = projects.ExtractProjects(allPages)
        th.AssertNoErr(t, err)

-       th.AssertEquals(t, len(allProjects), 0)
+       found = false
+       for _, project := range allProjects {
+               tools.PrintResource(t, project)
+
+               if project.Name == projectMain.Name {
+                       found = true
+               }
+       }
+
+       th.AssertEquals(t, found, false)

        // Search matching not all tags
        listOpts = projects.ListOpts{
@@ -325,4 +334,15 @@ func TestProjectsTags(t *testing.T) {
        tools.PrintResource(t, updatedProject)
        th.AssertEquals(t, len(updatedProject.Tags), 1)
        th.AssertEquals(t, updatedProject.Tags[0], "Tag1")
+
+       // Remove all Tags
+       updateOpts = projects.UpdateOpts{
+               Tags: &[]string{},
+       }
+
+       updatedProject, err = projects.Update(client, projectMain.ID, updateOpts).Extract()
+       th.AssertNoErr(t, err)
+
+       tools.PrintResource(t, updatedProject)
+       th.AssertEquals(t, len(updatedProject.Tags), 0)
 }

The last part is an addition to make sure that removing all tags is successful.

Our OpenLab tests have also been fixed, so you'll be able to see the test output in the OpenLab logs.

Let me know if you have any questions.

@randomswdev
Copy link
Copy Markdown
Contributor Author

Our OpenLab tests have also been fixed, so you'll be able to see the test output in the OpenLab logs.

Let me know if you have any questions.

Impemented the changes you suggested. I'm waiting for the tests to run and complete successfully.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Mar 5, 2020

Build succeeded.

Copy link
Copy Markdown
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

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

LGTM - thank you for your work on this!

@jtopjian jtopjian merged commit a043f1f into gophercloud:master Mar 6, 2020
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.

4 participants