-
Notifications
You must be signed in to change notification settings - Fork 63
Improves service offering resource #64
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
Merged
vishesh92
merged 11 commits into
apache:main
from
fabiomatavelli:fmatavelli-add-extra-resources
Mar 6, 2024
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
34a3801
chore: improve service offering resource
fabiomatavelli e8a79e6
doc: update readme
fabiomatavelli 47af773
ci: add acceptance test job
fabiomatavelli 0f3cf5a
docs: add service_offering doc
fabiomatavelli d4d11ea
Merge branch 'main' into fmatavelli-add-extra-resources
fabiomatavelli 11119dc
ci: add missing license header
fabiomatavelli 5b3dd8a
Merge branch 'main' into fmatavelli-add-extra-resources
fabiomatavelli 8793d8b
ci: create terraform project
fabiomatavelli 9525336
ci: add more versions to test
fabiomatavelli 26812d7
ci: use cmk to create extra resource
fabiomatavelli ba1f98f
Update cloudstack/resource_cloudstack_service_offering.go
fabiomatavelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| name: Acceptance Test | ||
|
|
||
| on: [push, pull_request] | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-testacc | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| testacc: | ||
| name: Acceptance Test | ||
| runs-on: ubuntu-22.04 | ||
| env: | ||
| CLOUDSTACK_API_URL: http://localhost:8080/client/api | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Set up Go | ||
| uses: actions/setup-go@v3 | ||
| with: | ||
| go-version: 1.19.x | ||
| - name: Wait Cloudstack to be ready | ||
| run: | | ||
| echo "Starting Cloudstack health check" | ||
| T=0 | ||
| until [ $T -gt 20 ] || curl -sfL http://localhost:8080 --output /dev/null | ||
| do | ||
| echo "Waiting for Cloudstack to be ready..." | ||
| ((T+=1)) | ||
| sleep 30 | ||
| done | ||
| - name: Setting up Cloudstack | ||
| run: | | ||
| docker exec $(docker container ls --format=json -l | jq -r .ID) python /root/tools/marvin/marvin/deployDataCenter.py -i /root/setup/dev/advanced.cfg | ||
|
yadvr marked this conversation as resolved.
|
||
| curl -sf --location "${CLOUDSTACK_API_URL}" \ | ||
| --header 'Content-Type: application/x-www-form-urlencoded' \ | ||
| --data-urlencode 'command=login' \ | ||
| --data-urlencode 'username=admin' \ | ||
| --data-urlencode 'password=password' \ | ||
| --data-urlencode 'response=json' \ | ||
| --data-urlencode 'domain=/' -j -c cookies.txt --output /dev/null | ||
|
|
||
| CLOUDSTACK_USER_ID=$(curl -fs "${CLOUDSTACK_API_URL}?command=listUsers&response=json" -b cookies.txt | jq -r '.listusersresponse.user[0].id') | ||
| CLOUDSTACK_API_KEY=$(curl -s "${CLOUDSTACK_API_URL}?command=getUserKeys&id=${CLOUDSTACK_USER_ID}&response=json" -b cookies.txt | jq -r '.getuserkeysresponse.userkeys.apikey') | ||
| CLOUDSTACK_SECRET_KEY=$(curl -fs "${CLOUDSTACK_API_URL}?command=getUserKeys&id=${CLOUDSTACK_USER_ID}&response=json" -b cookies.txt | jq -r '.getuserkeysresponse.userkeys.secretkey') | ||
|
|
||
| echo "::add-mask::$CLOUDSTACK_API_KEY" | ||
| echo "::add-mask::$CLOUDSTACK_SECRET_KEY" | ||
|
|
||
| echo "CLOUDSTACK_API_KEY=$CLOUDSTACK_API_KEY" >> $GITHUB_ENV | ||
| echo "CLOUDSTACK_SECRET_KEY=$CLOUDSTACK_SECRET_KEY" >> $GITHUB_ENV | ||
|
vishesh92 marked this conversation as resolved.
|
||
| - name: Install CMK | ||
| run: | | ||
| curl -sfL https://github.com/apache/cloudstack-cloudmonkey/releases/download/6.3.0/cmk.linux.x86-64 -o /usr/local/bin/cmk | ||
| chmod +x /usr/local/bin/cmk | ||
| - name: Create extra resources | ||
| run: | | ||
| cmk -u $CLOUDSTACK_API_URL -k $CLOUDSTACK_API_KEY -s $CLOUDSTACK_SECRET_KEY -o json create project name=terraform displaytext=terraform | ||
| - name: Run acceptance test | ||
| run: | | ||
| make testacc | ||
| services: | ||
| cloudstack-simulator: | ||
| image: apache/cloudstack-simulator:${{ matrix.cloudstack_version }} | ||
| ports: | ||
| - 8080:5050 | ||
| strategy: | ||
| matrix: | ||
| cloudstack_version: | ||
| - 4.17.2.0 | ||
| - 4.18.1.0 | ||
| - 4.19.0.0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| // | ||
|
|
||
| package cloudstack | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/apache/cloudstack-go/v2/cloudstack" | ||
| "github.com/hashicorp/terraform/helper/resource" | ||
| "github.com/hashicorp/terraform/terraform" | ||
| ) | ||
|
|
||
| func TestAccCloudStackServiceOffering_basic(t *testing.T) { | ||
| var so cloudstack.ServiceOffering | ||
| resource.Test(t, resource.TestCase{ | ||
| PreCheck: func() { testAccPreCheck(t) }, | ||
| Providers: testAccProviders, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: testAccCloudStackServiceOffering_basic, | ||
| Check: resource.ComposeTestCheckFunc( | ||
| testAccCheckCloudStackServiceOfferingExists("cloudstack_service_offering.test1", &so), | ||
| resource.TestCheckResourceAttr("cloudstack_service_offering.test1", "cpu_number", "2"), | ||
| resource.TestCheckResourceAttr("cloudstack_service_offering.test1", "cpu_speed", "2200"), | ||
| resource.TestCheckResourceAttr("cloudstack_service_offering.test1", "memory", "8096"), | ||
| ), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| const testAccCloudStackServiceOffering_basic = ` | ||
| resource "cloudstack_service_offering" "test1" { | ||
| name = "service_offering_1" | ||
| display_text = "Test" | ||
| cpu_number = 2 | ||
| cpu_speed = 2200 | ||
| memory = 8096 | ||
| } | ||
| ` | ||
|
|
||
| func testAccCheckCloudStackServiceOfferingExists(n string, so *cloudstack.ServiceOffering) resource.TestCheckFunc { | ||
| return func(s *terraform.State) error { | ||
| rs, ok := s.RootModule().Resources[n] | ||
| if !ok { | ||
| return fmt.Errorf("Not found: %s", n) | ||
| } | ||
|
|
||
| if rs.Primary.ID == "" { | ||
| return fmt.Errorf("No service offering ID is set") | ||
| } | ||
|
|
||
| cs := testAccProvider.Meta().(*cloudstack.CloudStackClient) | ||
| resp, _, err := cs.ServiceOffering.GetServiceOfferingByID(rs.Primary.ID) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if resp.Id != rs.Primary.ID { | ||
| return fmt.Errorf("Service offering not found") | ||
| } | ||
|
|
||
| *so = *resp | ||
|
|
||
| return nil | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.