Skip to content

Commit

Permalink
add test data for gce.get_gce_public_licences
Browse files Browse the repository at this point in the history
fix: 367682890
Change-Id: I99a324d4136e832a4aa97a73c2f07d7e74033aa6
GitOrigin-RevId: 4286dd2959669614942c566eb1e95cfc22d1ca87
  • Loading branch information
vinay-vgs authored and copybara-github committed Sep 19, 2024
1 parent 87bf38a commit b827ca0
Show file tree
Hide file tree
Showing 20 changed files with 2,296 additions and 4 deletions.
5 changes: 4 additions & 1 deletion gcpdiag/lint/gce/snapshots/WARN_2022_012.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* gce/WARN/2022_012: PAYG licensed Windows instance can reach KMS to activate
(Error: 'windows-cloud') [SKIP]
- projects/gcpdiag-gce1-aaaa/zones/europe-west4-a/instances/gce1 [ OK ]
- projects/gcpdiag-gce1-aaaa/zones/europe-west4-a/instances/windows-test [SKIP]
No PAYG licence attached to this instance
- projects/gcpdiag-gce1-aaaa/zones/europe-west4-b/instances/gce1 [ OK ]

47 changes: 46 additions & 1 deletion gcpdiag/queries/apis_stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,52 @@
'gcpdiag-gke4-runbook':
pathlib.Path(__file__).parents[2] / 'test-data/gke4/json-dumps',
'12340033':
pathlib.Path(__file__).parents[2] / 'test-data/gke4/json-dumps'
pathlib.Path(__file__).parents[2] / 'test-data/gke4/json-dumps',
'centos-cloud':
pathlib.Path(__file__).parents[2] /
'test-data/gce-image-license/json-dumps',
'cos-cloud':
pathlib.Path(__file__).parents[2] /
'test-data/gce-image-license/json-dumps',
'debian-cloud':
pathlib.Path(__file__).parents[2] /
'test-data/gce-image-license/json-dumps',
'fedora-cloud':
pathlib.Path(__file__).parents[2] /
'test-data/gce-image-license/json-dumps',
'fedora-coreos-cloud':
pathlib.Path(__file__).parents[2] /
'test-data/gce-image-license/json-dumps',
'opensuse-cloud':
pathlib.Path(__file__).parents[2] /
'test-data/gce-image-license/json-dumps',
'rhel-cloud':
pathlib.Path(__file__).parents[2] /
'test-data/gce-image-license/json-dumps',
'rhel-sap-cloud':
pathlib.Path(__file__).parents[2] /
'test-data/gce-image-license/json-dumps',
'rocky-linux-cloud':
pathlib.Path(__file__).parents[2] /
'test-data/gce-image-license/json-dumps',
'suse-cloud':
pathlib.Path(__file__).parents[2] /
'test-data/gce-image-license/json-dumps',
'suse-sap-cloud':
pathlib.Path(__file__).parents[2] /
'test-data/gce-image-license/json-dumps',
'ubuntu-os-cloud':
pathlib.Path(__file__).parents[2] /
'test-data/gce-image-license/json-dumps',
'ubuntu-os-pro-cloud':
pathlib.Path(__file__).parents[2] /
'test-data/gce-image-license/json-dumps',
'windows-cloud':
pathlib.Path(__file__).parents[2] /
'test-data/gce-image-license/json-dumps',
'windows-sql-cloud':
pathlib.Path(__file__).parents[2] /
'test-data/gce-image-license/json-dumps',
}

# set to a value higher than 0 to emulate API temp. failure
Expand Down
4 changes: 3 additions & 1 deletion gcpdiag/queries/gce_stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ def list(self, project, zone=None, returnPartialSuccess=None, fields=None):
f'compute-{self.mock_state}-{zone}',
default=f'compute-{self.mock_state}-empty',
)
elif self.mock_state in ['regions', 'templates', 'zones', 'licenses']:
elif self.mock_state in ['regions', 'templates', 'zones']:
return apis_stub.RestCallStub(project, f'compute-{self.mock_state}')
elif self.mock_state in ['licenses']:
return apis_stub.RestCallStub(project, f'{project}-licenses')
else:
raise RuntimeError(f"can't list for mock state {self.mock_state}")

Expand Down
3 changes: 2 additions & 1 deletion gcpdiag/queries/gce_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
DUMMY_ZONE2 = 'europe-west1-b'
DUMMY_ZONE3 = 'europe-west4-b'
DUMMY_PROJECT_NAME = 'gcpdiag-gce1-aaaa'
DUMMY_LICENSE_PROJECT_NAME = 'windows-cloud'
DUMMY_PROJECT_NR = '12340001'
DUMMY_DEFAULT_NAME = 'default'
DUMMY_INSTANCE1_NAME = 'gce1'
Expand Down Expand Up @@ -328,7 +329,7 @@ def test_is_public_machine(self):
assert instance.is_public_machine() is True

def test_check_license(self):
licenses = gce.get_gce_public_licences(DUMMY_PROJECT_NAME)
licenses = gce.get_gce_public_licences(DUMMY_LICENSE_PROJECT_NAME)
payg_licenses = [x for x in licenses if not x.endswith('-byol')]
instance = gce.get_instance(project_id=DUMMY_PROJECT_NAME,
zone=DUMMY_ZONE,
Expand Down
40 changes: 40 additions & 0 deletions test-data/gce-image-license/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
CURL = ../../bin/curl-wrap.sh
JSON_CLEANER = ../../bin/json-cleaner

CENTOS_CLOUD= centos-cloud
COS_CLOUD= cos-cloud
DEBIAN_CLOUD= debian-cloud
FEDORA_CLOUD= fedora-cloud
FEDORA_CORECOS_CLOUD= fedora-coreos-cloud
OPENSUSE_CLOUD= opensuse-cloud
RHEL_CLOUD= rhel-cloud
RHEL_SAP_CLOUD= rhel-sap-cloud
ROCKY_LINUX_CLOUD= rocky-linux-cloud
SUSE_CLOUD= suse-cloud
SUSE_SAP_CLOUD= suse-sap-cloud
UBUNTU_OS_CLOUD= ubuntu-os-cloud
UBUNTU_OS_PRO_CLOUD= ubuntu-os-pro-cloud
WINDOW_CLOUD= windows-cloud
WINDOWS_SQL_CLOUD= windows-sql-cloud

all: \
json-dumps/${CENTOS_CLOUD}-licenses.json \
json-dumps/${COS_CLOUD}-licenses.json \
json-dumps/${DEBIAN_CLOUD}-licenses.json \
json-dumps/${FEDORA_CLOUD}-licenses.json \
json-dumps/${FEDORA_CORECOS_CLOUD}-licenses.json \
json-dumps/${OPENSUSE_CLOUD}-licenses.json \
json-dumps/${RHEL_CLOUD}-licenses.json \
json-dumps/${RHEL_SAP_CLOUD}-licenses.json \
json-dumps/${ROCKY_LINUX_CLOUD}-licenses.json \
json-dumps/${SUSE_CLOUD}-licenses.json \
json-dumps/${SUSE_SAP_CLOUD}-licenses.json \
json-dumps/${UBUNTU_OS_CLOUD}-licenses.json \
json-dumps/${UBUNTU_OS_PRO_CLOUD}-licenses.json \
json-dumps/${WINDOW_CLOUD}-licenses.json \
json-dumps/${WINDOWS_SQL_CLOUD}-licenses.json

json-dumps/%-licenses.json:
$(CURL) -fsS \
'https://compute.googleapis.com/compute/v1/projects/$*/global/licenses' \
--header "Content-Type:text/json" > $@
61 changes: 61 additions & 0 deletions test-data/gce-image-license/json-dumps/centos-cloud-licenses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"id": "projects/centos-cloud/global/licenses",
"items": [
{
"kind": "compute#license",
"name": "centos-6",
"chargesUseFee": true,
"id": "6261635378630811686",
"licenseCode": "1000206",
"creationTimestamp": "2016-02-09T14:08:14.000-08:00",
"description": "CentOS 6",
"transferable": true,
"selfLink": "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/licenses/centos-6"
},
{
"kind": "compute#license",
"name": "centos-7",
"chargesUseFee": true,
"id": "1590725888655155238",
"licenseCode": "1000207",
"creationTimestamp": "2016-02-09T14:08:14.000-08:00",
"description": "CentOS 7",
"transferable": true,
"selfLink": "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/licenses/centos-7"
},
{
"kind": "compute#license",
"name": "centos-8",
"chargesUseFee": false,
"id": "3549388059678600306",
"licenseCode": "5731035067256925298",
"creationTimestamp": "2019-09-24T10:30:05.016-07:00",
"description": "CentOS 8",
"transferable": true,
"selfLink": "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/licenses/centos-8"
},
{
"kind": "compute#license",
"name": "centos-stream",
"chargesUseFee": false,
"id": "2847851129470332745",
"licenseCode": "3197331720697687881",
"creationTimestamp": "2020-12-29T12:29:26.821-08:00",
"description": "CentOS Stream",
"transferable": true,
"selfLink": "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/licenses/centos-stream"
},
{
"kind": "compute#license",
"name": "centos-stream-9",
"chargesUseFee": false,
"id": "8153611294265844894",
"licenseCode": "2587764519704208542",
"creationTimestamp": "2022-02-01T12:39:13.879-08:00",
"description": "CentOS Stream 9",
"transferable": true,
"selfLink": "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/licenses/centos-stream-9"
}
],
"selfLink": "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/licenses"
}
50 changes: 50 additions & 0 deletions test-data/gce-image-license/json-dumps/cos-cloud-licenses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"id": "projects/cos-cloud/global/licenses",
"items": [
{
"kind": "compute#license",
"name": "cos",
"chargesUseFee": false,
"id": "1860921057156066203",
"licenseCode": "1001010",
"creationTimestamp": "2017-01-13T12:51:38.000-08:00",
"description": "Container-Optimized OS from Google",
"transferable": true,
"selfLink": "https://www.googleapis.com/compute/v1/projects/cos-cloud/global/licenses/cos"
},
{
"kind": "compute#license",
"name": "cos-gpu",
"chargesUseFee": false,
"id": "7123420343221295763",
"licenseCode": "146969651383835282",
"creationTimestamp": "2017-10-02T13:41:33.043-07:00",
"description": "Container-Optimized OS from Google, with GPU drivers",
"transferable": true,
"selfLink": "https://www.googleapis.com/compute/v1/projects/cos-cloud/global/licenses/cos-gpu"
},
{
"kind": "compute#license",
"name": "cos-pcid",
"chargesUseFee": false,
"id": "9020039035948176868",
"licenseCode": "6880041984096540132",
"creationTimestamp": "2018-08-15T15:36:59.739-07:00",
"description": "Container-Optimized OS - PCID Whitelisted",
"transferable": true,
"selfLink": "https://www.googleapis.com/compute/v1/projects/cos-cloud/global/licenses/cos-pcid"
},
{
"kind": "compute#license",
"name": "cos-st",
"chargesUseFee": false,
"id": "7258840043588497590",
"licenseCode": "9084803053990260918",
"creationTimestamp": "2017-10-04T00:31:37.769-07:00",
"description": "Container-Optimized OS from Google, with Snaggletooth drivers",
"transferable": true,
"selfLink": "https://www.googleapis.com/compute/v1/projects/cos-cloud/global/licenses/cos-st"
}
],
"selfLink": "https://www.googleapis.com/compute/v1/projects/cos-cloud/global/licenses"
}
72 changes: 72 additions & 0 deletions test-data/gce-image-license/json-dumps/debian-cloud-licenses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"id": "projects/debian-cloud/global/licenses",
"items": [
{
"kind": "compute#license",
"name": "debian-10-buster",
"chargesUseFee": false,
"id": "7165099968554055853",
"licenseCode": "5543610867827062957",
"creationTimestamp": "2018-08-22T17:56:34.778-07:00",
"description": "Debian 10 Buster",
"transferable": true,
"selfLink": "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/licenses/debian-10-buster"
},
{
"kind": "compute#license",
"name": "debian-11-bullseye",
"chargesUseFee": false,
"id": "8474191643257863115",
"licenseCode": "3853522013536123851",
"creationTimestamp": "2021-03-23T12:44:36.568-07:00",
"description": "Debian 11 Bullseye",
"transferable": true,
"selfLink": "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/licenses/debian-11-bullseye"
},
{
"kind": "compute#license",
"name": "debian-12-bookworm",
"chargesUseFee": false,
"id": "50032240371219040",
"licenseCode": "2147286739765738111",
"creationTimestamp": "2023-03-08T13:56:32.072-08:00",
"description": "Debian 12 Bookworm",
"transferable": true,
"selfLink": "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/licenses/debian-12-bookworm"
},
{
"kind": "compute#license",
"name": "debian-7-wheezy",
"chargesUseFee": true,
"id": "5548643783560585255",
"licenseCode": "1000203",
"creationTimestamp": "2016-02-09T14:08:14.000-08:00",
"description": "Debian 7 Wheezy",
"transferable": true,
"selfLink": "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/licenses/debian-7-wheezy"
},
{
"kind": "compute#license",
"name": "debian-8-jessie",
"chargesUseFee": true,
"id": "4583190536202936358",
"licenseCode": "1000204",
"creationTimestamp": "2016-02-09T14:08:14.000-08:00",
"description": "Debian 8 Jessie",
"transferable": true,
"selfLink": "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/licenses/debian-8-jessie"
},
{
"kind": "compute#license",
"name": "debian-9-stretch",
"chargesUseFee": true,
"id": "422202477258924070",
"licenseCode": "1000205",
"creationTimestamp": "2016-02-09T14:08:14.000-08:00",
"description": "Debian 9 Stretch",
"transferable": true,
"selfLink": "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/licenses/debian-9-stretch"
}
],
"selfLink": "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/licenses"
}
Loading

0 comments on commit b827ca0

Please sign in to comment.