Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Added integration tests#481

Open
Sharpz7 wants to merge 2 commits intoopenstack-exporter:mainfrom
Sharpz7:integration-tests
Open

Added integration tests#481
Sharpz7 wants to merge 2 commits intoopenstack-exporter:mainfrom
Sharpz7:integration-tests

Conversation

@Sharpz7
Copy link
Collaborator

@Sharpz7 Sharpz7 commented Sep 3, 2025

This should help make trusting new changes easier.

@Sharpz7 Sharpz7 added the priority Priority PR or Issue to help with tracking. label Sep 3, 2025
@Sharpz7
Copy link
Collaborator Author

Sharpz7 commented Sep 3, 2025

This is copying a significant amount of code from https://github.com/gophercloud/gophercloud/tree/main/internal/acceptance. I am going to create a ticket there about potentially trying to expose this code out instead of copying it.

@Sharpz7 Sharpz7 removed the priority Priority PR or Issue to help with tracking. label Sep 3, 2025
@Sharpz7 Sharpz7 marked this pull request as draft September 3, 2025 04:18
This was referenced Oct 30, 2025
@Sharpz7 Sharpz7 marked this pull request as ready for review December 2, 2025 04:43
@Sharpz7 Sharpz7 requested a review from Copilot December 2, 2025 04:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces comprehensive integration tests for the OpenStack exporter, enabling automated testing against live OpenStack services (Ironic, Nova, Neutron, Glance, Keystone, Placement) via DevStack in CI. The tests validate that the exporter correctly generates Prometheus metrics from real OpenStack resources.

Key Changes

  • Added integration test infrastructure with helper packages for creating test resources and clients
  • Created service-specific integration test suites (baremetal, compute, networking, images, identity, placement)
  • Set up GitHub Actions workflows to run integration tests on pull requests using DevStack

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 18 comments.

Show a summary per file
File Description
script/stackenv Bash script to prepare DevStack testing environment with required resources and environment variables
script/integration-suites/* Individual test runner scripts for each OpenStack service integration test suite
script/collectlogs Utility script to collect diagnostic logs after integration test failures
integration/utils.go Core integration test utilities for starting the OpenStack exporter
integration/tools/tools.go Helper functions for waiting, random generation, and resource printing in tests
integration/tools/pkg.go Build tags and package documentation for test tools
integration/funcs/compute.go Helper functions for creating and managing compute resources in tests
integration/funcs/baremetal.go Helper functions for creating and managing baremetal nodes in tests
integration/funcs/pkg.go Build tags and package documentation for test resource functions
integration/clients/clients.go OpenStack service client creation functions for various services
integration/clients/conditions.go Test skip conditions for different OpenStack configurations and features
integration/clients/http.go HTTP round tripper with request/response logging and header redaction
integration/*_test.go Integration test files validating exporter metrics for each OpenStack service
.github/workflows/integration-*.yaml GitHub Actions workflows for running integration tests in CI
.github/workflows/ci.yaml Updated to exclude integration tests from unit test runs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +28 to +73
fetchMetrics := func(
url string,
maxTries int,
) (resp *http.Response, body []byte, err error) {
for i := 0; i < maxTries; i++ {
resp, err = http.Get(url)
if err == nil && resp.StatusCode == http.StatusOK {
defer resp.Body.Close()
body, err = io.ReadAll(resp.Body)
if err == nil {
return resp, body, nil
}
t.Logf(
"Attempt %d: Failed to read response body: %v",
i+1,
err,
)
} else {
var statusCode int
if resp != nil {
statusCode = resp.StatusCode
}
t.Logf(
"Attempt %d: Failed to get metrics, status code: %d, error: %v",
i+1,
statusCode,
err,
)
}
if resp != nil && resp.Body != nil {
resp.Body.Close()
}
time.Sleep(1 * time.Second)
}
if err != nil {
return nil, nil, fmt.Errorf(
"failed to get metrics after %d retries: %w",
maxTries,
err,
)
}
return nil, nil, fmt.Errorf(
"failed to get metrics after %d retries, but the error is nil (this should not happen)",
maxTries,
)
}
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

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

There's significant code duplication in the fetchMetrics function across multiple test files (networking_test.go, images_test.go, identity_test.go, baremetal_test.go). This identical function should be extracted to a shared helper in integration/utils.go or a similar location to improve maintainability.

Copilot uses AI. Check for mistakes.
@openstack-exporter openstack-exporter deleted a comment from Copilot AI Dec 2, 2025
CI Fixes

Fixing more lint errors

Tried to make tests more specific

Fixed issues

Fixes

Fixes

More fixes

Trying more

Test

Fix

Testing

Testing

Changes

Removing placement

Trying things out

More changes

Testing

Trying things

Fixes

Fixes

chore(deps): bump actions/checkout from 4 to 6

Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Commits](actions/checkout@v4...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

Update integration/funcs/compute.go

Co-authored-by: Copilot <[email protected]>

Update script/stackenv

Co-authored-by: Copilot <[email protected]>

chore(deps): bump reviewdog/action-actionlint from 1.66.1 to 1.69.0

Bumps [reviewdog/action-actionlint](https://github.com/reviewdog/action-actionlint) from 1.66.1 to 1.69.0.
- [Release notes](https://github.com/reviewdog/action-actionlint/releases)
- [Commits](reviewdog/action-actionlint@e37e2ca...437bbe9)

---
updated-dependencies:
- dependency-name: reviewdog/action-actionlint
  dependency-version: 1.69.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
@openstack-exporter openstack-exporter deleted a comment from Copilot AI Dec 2, 2025
@openstack-exporter openstack-exporter deleted a comment from Copilot AI Dec 2, 2025
@openstack-exporter openstack-exporter deleted a comment from Copilot AI Dec 2, 2025
@openstack-exporter openstack-exporter deleted a comment from Copilot AI Dec 2, 2025
@openstack-exporter openstack-exporter deleted a comment from Copilot AI Dec 2, 2025
@Sharpz7
Copy link
Collaborator Author

Sharpz7 commented Dec 2, 2025

Service Test Name Coverage
Baremetal (Ironic) TestBaremetalIntegration openstack_ironic_node metric with labels (console_enabled, deploy_kernel, deploy_ramdisk, id, maintenance, name, power_state, provision_state, resource_class, retired, retired_reason); openstack_ironic_up metric; metric metadata (HELP and TYPE comments)
Compute (Nova) TestComputeIntegration openstack_nova_server_status metric for specific server; openstack_nova_total_vms metric; openstack_nova_server_local_gb metric; availability_zone label on server status; openstack_nova_quota_instances for admin tenant; openstack_nova_quota_key_pairs limit for admin tenant
Identity (Keystone) TestIdentityIntegration openstack_identity_up metric with value 1; metric metadata (HELP and TYPE comments); core metrics presence (openstack_identity_projects, openstack_identity_users, openstack_identity_domains); openstack_identity_project_info line format with labels (id, name, domain_id, enabled, parent_id)
Image (Glance) TestImagesIntegration openstack_glance_up metric with value 1; metric metadata (HELP and TYPE comments); core metrics presence (openstack_glance_images, openstack_glance_image_bytes, openstack_glance_image_created_at); openstack_glance_image_bytes line format; openstack_glance_image_created_at line format with labels (hidden, id, name, status, tenant_id, visibility)
Network (Neutron) TestNetworkingIntegration openstack_neutron_up metric with value 1; metric metadata (HELP and TYPE comments); core metrics presence (openstack_neutron_networks, openstack_neutron_ports, openstack_neutron_subnets, openstack_neutron_router); openstack_neutron_network line format with labels (id, name, is_external, is_shared, provider_network_type)

@Sharpz7
Copy link
Collaborator Author

Sharpz7 commented Dec 2, 2025

I think the main thing to not is BASIS_OPS for ironic is false. For some reason, this makes the tests pass, where they didn't before

@Sharpz7
Copy link
Collaborator Author

Sharpz7 commented Dec 4, 2025

@vooon - I'd appreciate your feedback on this in any capacity

Copy link
Contributor

@vooon vooon left a comment

Choose a reason for hiding this comment

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

@Sharpz7 here are a few notes.

Also might be helpful to setup slog to show debug.

- name: Checkout go
uses: actions/setup-go@v5
with:
go-version: '^1.22'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think better to use that:

      - uses: actions/setup-go@v6
        with:
          go-version-file: go.mod

metricsURL := "http://localhost:9180/metrics"

// Helper function to fetch metrics with retries
fetchMetrics := func(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think here Copilot's right - since it's the same, i'd move it to general function or make a test suite.

)
}

time.Sleep(10 * time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to avoid sleeps, if possible.

return nil, err
}

client, err := openstack.AuthenticatedClient(context.TODO(), ao)
Copy link
Contributor

Choose a reason for hiding this comment

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

Again good candidate for test suite. Also i'd probably add some timeout to the context - just to fail if there some problem with connectivity, instead of hung till CI timeout.


// LogRoundTripper satisfies the http.RoundTripper interface and is used to
// customize the default http client RoundTripper to allow logging.
type LogRoundTripper struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably easier to use logger from gophercloud utils (present for both v1 and v2).
https://github.com/gophercloud/utils/blob/main/client/client.go

@Sharpz7
Copy link
Collaborator Author

Sharpz7 commented Dec 5, 2025

@vooon appreciate this. Thank you!

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.

3 participants