From 69cba08f2deb1e7526315d16e4f9de26dd73b970 Mon Sep 17 00:00:00 2001 From: georgiyekkert Date: Mon, 23 Aug 2021 12:41:37 -0700 Subject: [PATCH 01/13] tests: add cases for int64 field, map pagination, field that start with capital letter (#105) * tests: int64, capitalletter, map pagination * unused import * tests: review fix * tests:review fix --- tests/system/test_instance_group.py | 20 +++++++---- tests/system/test_pagination.py | 22 ++++++++++++ tests/system/test_smoke.py | 56 +++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 7 deletions(-) diff --git a/tests/system/test_instance_group.py b/tests/system/test_instance_group.py index 3e6a37226..abb468047 100644 --- a/tests/system/test_instance_group.py +++ b/tests/system/test_instance_group.py @@ -135,10 +135,16 @@ def test_instance_group_resize(self): ) self.assertEqual(instance_group.target_size, 1) - # Resize to zero fails, uncomment once fixed b/189145532. - # resize_0_op = self.igm_client.resize(project=self.DEFAULT_PROJECT, - # zone=self.DEFAULT_ZONE, size=0, instance_group_manager=igm_name) - # self.wait_for_zonal_operation(resize_0_op.name) - # igm = self.igm_client.get(project=self.DEFAULT_PROJECT, zone=self.DEFAULT_ZONE, - # instance_group_manager=igm_name) - # self.assertEqual(igm.target_size, 0) + resize_0_op = self.igm_client.resize( + project=self.DEFAULT_PROJECT, + zone=self.DEFAULT_ZONE, + size=0, + instance_group_manager=igm_name, + ) + self.wait_for_zonal_operation(resize_0_op.name) + igm = self.igm_client.get( + project=self.DEFAULT_PROJECT, + zone=self.DEFAULT_ZONE, + instance_group_manager=igm_name, + ) + self.assertEqual(igm.target_size, 0) diff --git a/tests/system/test_pagination.py b/tests/system/test_pagination.py index 3f8f4e546..79781004b 100644 --- a/tests/system/test_pagination.py +++ b/tests/system/test_pagination.py @@ -12,8 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +import collections +from google.cloud.compute_v1.services.accelerator_types.client import ( + AcceleratorTypesClient, +) from google.cloud.compute_v1.services.zones.client import ZonesClient +from google.cloud.compute_v1.types import AggregatedListAcceleratorTypesRequest from google.cloud.compute_v1.types import ListZonesRequest from tests.system.base import TestBase @@ -65,3 +70,20 @@ def test_auto_paging(self): presented = True break self.assertTrue(presented) + + +class TestPaginationAggregatedList(TestBase): + def setUp(self) -> None: + super().setUp() + + def test_auto_paging_map_response(self): + client = AcceleratorTypesClient() + request = AggregatedListAcceleratorTypesRequest( + project=self.DEFAULT_PROJECT, max_results=3 + ) + result = client.aggregated_list(request=request) + zone_acc_types = collections.defaultdict(list) + for zone, types in result: + zone_acc_types[zone].extend(at.name for at in types.accelerator_types) + default_zone = "zones/" + self.DEFAULT_ZONE + self.assertIn("nvidia-tesla-t4", zone_acc_types[default_zone]) diff --git a/tests/system/test_smoke.py b/tests/system/test_smoke.py index 36c6fbddf..0668cea6c 100644 --- a/tests/system/test_smoke.py +++ b/tests/system/test_smoke.py @@ -16,8 +16,14 @@ import time import google.api_core.exceptions +from google.cloud.compute_v1.services.firewalls.client import FirewallsClient +from google.cloud.compute_v1.services.images.client import ImagesClient from google.cloud.compute_v1.services.instances.client import InstancesClient from google.cloud.compute_v1.types import ( + Allowed, + Firewall, + Image, + InsertImageRequest, InsertInstanceRequest, Instance, AttachedDisk, @@ -189,3 +195,53 @@ def insert_instance(self): operation = self.client.insert(request=request) self.wait_for_zonal_operation(operation.name) self.instances.append(self.name) + + +class TestComputeImages(TestBase): + def setUp(self) -> None: + super().setUp() + + def test_int64(self): + # we want to test a field with format:int64 + name = self.get_unique_name("image") + license_codes = [5543610867827062957] + image = Image( + name=name, + license_codes=license_codes, + source_image="projects/debian-cloud/global/images/debian-10-buster-v20210721", + ) + images_client = ImagesClient(transport="rest") + request = InsertImageRequest(project=self.DEFAULT_PROJECT, image_resource=image) + op = images_client.insert(request) + try: + self.wait_for_global_operation(op.name) + + fetched = images_client.get(project=self.DEFAULT_PROJECT, image=name) + self.assertEqual(fetched.license_codes, license_codes) + self.assertEqual(fetched.name, name) + finally: + images_client.delete(project=self.DEFAULT_PROJECT, image=name) + + +class TestComputeFirewalls(TestBase): + def setUp(self): + super().setUp() + + def test_capital_letter_field(self): + # we want to test a field like "IPProtocol" + name = self.get_unique_name("firewall") + client = FirewallsClient() + firewall = Firewall( + name=name, + source_ranges=["0.0.0.0/0"], + allowed=[Allowed(I_p_protocol="tcp", ports=["80"])], + ) + op = client.insert(project=self.DEFAULT_PROJECT, firewall_resource=firewall) + try: + self.wait_for_global_operation(op.name) + + fetched = client.get(project=self.DEFAULT_PROJECT, firewall=name) + self.assertEqual(fetched.allowed[0].I_p_protocol, "tcp") + self.assertEqual(fetched.allowed[0].ports, ["80"]) + finally: + client.delete(project=self.DEFAULT_PROJECT, firewall=name) From 22a23d5fb7a5588be96a238be541817c641d068f Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 27 Aug 2021 12:50:38 -0400 Subject: [PATCH 02/13] chore: migrate default branch from master to main (#110) --- .kokoro/build.sh | 2 +- .kokoro/test-samples-impl.sh | 2 +- CONTRIBUTING.rst | 12 ++++---- docs/conf.py | 10 +++---- synth.py | 54 ++++++++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 13 deletions(-) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index cf739ec89..35c57a936 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -41,7 +41,7 @@ python3 -m pip install --upgrade --quiet nox python3 -m nox --version # If this is a continuous build, send the test log to the FlakyBot. -# See https://github.com/googleapis/repo-automation-bots/tree/master/packages/flakybot. +# See https://github.com/googleapis/repo-automation-bots/tree/main/packages/flakybot. if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]]; then cleanup() { chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot diff --git a/.kokoro/test-samples-impl.sh b/.kokoro/test-samples-impl.sh index 311a8d54b..8a324c9c7 100755 --- a/.kokoro/test-samples-impl.sh +++ b/.kokoro/test-samples-impl.sh @@ -80,7 +80,7 @@ for file in samples/**/requirements.txt; do EXIT=$? # If this is a periodic build, send the test log to the FlakyBot. - # See https://github.com/googleapis/repo-automation-bots/tree/master/packages/flakybot. + # See https://github.com/googleapis/repo-automation-bots/tree/main/packages/flakybot. if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot $KOKORO_GFILE_DIR/linux_amd64/flakybot diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 6d765f117..8a73ed9c7 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -50,9 +50,9 @@ You'll have to create a development environment using a Git checkout: # Configure remotes such that you can pull changes from the googleapis/python-compute # repository into your local repository. $ git remote add upstream git@github.com:googleapis/python-compute.git - # fetch and merge changes from upstream into master + # fetch and merge changes from upstream into main $ git fetch upstream - $ git merge upstream/master + $ git merge upstream/main Now your local repo is set up such that you will push changes to your GitHub repo, from which you can submit a pull request. @@ -110,12 +110,12 @@ Coding Style variables:: export GOOGLE_CLOUD_TESTING_REMOTE="upstream" - export GOOGLE_CLOUD_TESTING_BRANCH="master" + export GOOGLE_CLOUD_TESTING_BRANCH="main" By doing this, you are specifying the location of the most up-to-date version of ``python-compute``. The the suggested remote name ``upstream`` should point to the official ``googleapis`` checkout and the - the branch should be the main branch on that remote (``master``). + the branch should be the main branch on that remote (``main``). - This repository contains configuration for the `pre-commit `__ tool, which automates checking @@ -209,7 +209,7 @@ The `description on PyPI`_ for the project comes directly from the ``README``. Due to the reStructuredText (``rst``) parser used by PyPI, relative links which will work on GitHub (e.g. ``CONTRIBUTING.rst`` instead of -``https://github.com/googleapis/python-compute/blob/master/CONTRIBUTING.rst``) +``https://github.com/googleapis/python-compute/blob/main/CONTRIBUTING.rst``) may cause problems creating links or rendering the description. .. _description on PyPI: https://pypi.org/project/google-cloud-compute @@ -234,7 +234,7 @@ We support: Supported versions can be found in our ``noxfile.py`` `config`_. -.. _config: https://github.com/googleapis/python-compute/blob/master/noxfile.py +.. _config: https://github.com/googleapis/python-compute/blob/main/noxfile.py We also explicitly decided to support Python 3 beginning with version 3.6. diff --git a/docs/conf.py b/docs/conf.py index 957061016..14a089750 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -76,8 +76,8 @@ # The encoding of source files. # source_encoding = 'utf-8-sig' -# The master toctree document. -master_doc = "index" +# The root toctree document. +root_doc = "index" # General information about the project. project = "google-cloud-compute" @@ -280,7 +280,7 @@ # author, documentclass [howto, manual, or own class]). latex_documents = [ ( - master_doc, + root_doc, "google-cloud-compute.tex", "google-cloud-compute Documentation", author, @@ -315,7 +315,7 @@ # (source start file, name, description, authors, manual section). man_pages = [ ( - master_doc, + root_doc, "google-cloud-compute", "google-cloud-compute Documentation", [author], @@ -334,7 +334,7 @@ # dir menu entry, description, category) texinfo_documents = [ ( - master_doc, + root_doc, "google-cloud-compute", "google-cloud-compute Documentation", author, diff --git a/synth.py b/synth.py index a6eb56c07..12f1cbad4 100644 --- a/synth.py +++ b/synth.py @@ -45,6 +45,60 @@ templated_files, excludes=[".coveragerc"] # the microgenerator has a good coveragerc file ) +# Remove the replacements below once https://github.com/googleapis/synthtool/pull/1188 is merged + +# Update googleapis/repo-automation-bots repo to main in .kokoro/*.sh files +s.replace(".kokoro/*.sh", "repo-automation-bots/tree/master", "repo-automation-bots/tree/main") + +# Customize CONTRIBUTING.rst to replace master with main +s.replace( + "CONTRIBUTING.rst", + "fetch and merge changes from upstream into master", + "fetch and merge changes from upstream into main", +) + +s.replace( + "CONTRIBUTING.rst", + "git merge upstream/master", + "git merge upstream/main", +) + +s.replace( + "CONTRIBUTING.rst", + """export GOOGLE_CLOUD_TESTING_BRANCH=\"master\"""", + """export GOOGLE_CLOUD_TESTING_BRANCH=\"main\"""", +) + +s.replace( + "CONTRIBUTING.rst", + "remote \(``master``\)", + "remote (``main``)", +) + +s.replace( + "CONTRIBUTING.rst", + "blob/master/CONTRIBUTING.rst", + "blob/main/CONTRIBUTING.rst", +) + +s.replace( + "CONTRIBUTING.rst", + "blob/master/noxfile.py", + "blob/main/noxfile.py", +) + +s.replace( + "docs/conf.py", + "master_doc", + "root_doc", +) + +s.replace( + "docs/conf.py", + "# The master toctree document.", + "# The root toctree document.", +) + # -------------------------------------------------------------------------- # Samples templates # -------------------------------------------------------------------------- From 291dfb149a6a8d72cc2fa76ec5af06eda5d33f41 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 31 Aug 2021 04:40:27 -0700 Subject: [PATCH 03/13] chore: disable dependency dashboard (#113) This PR was generated using Autosynth. :rainbow: Synth log will be available here: https://source.cloud.google.com/results/invocations/a397d906-07cc-411d-9768-30d96bd30393/targets - [ ] To automatically regenerate this PR, check this box. (May take up to 24 hours.) --- renovate.json | 4 +++- synth.metadata | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/renovate.json b/renovate.json index c04895563..9fa8816fe 100644 --- a/renovate.json +++ b/renovate.json @@ -1,6 +1,8 @@ { "extends": [ - "config:base", ":preserveSemverRanges" + "config:base", + ":preserveSemverRanges", + ":disableDependencyDashboard" ], "ignorePaths": [".pre-commit-config.yaml"], "pip_requirements": { diff --git a/synth.metadata b/synth.metadata index f6cf511d6..917af3a46 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,7 +4,7 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-compute.git", - "sha": "2eca2f305dea26c03703a618061bec8f2b6bf316" + "sha": "22a23d5fb7a5588be96a238be541817c641d068f" } }, { From 671bd6ac7c0311dde34a405c7607161ebab13cd5 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 31 Aug 2021 17:38:15 +0200 Subject: [PATCH 04/13] chore(deps): update dependency pytest to v6.2.5 (#112) Co-authored-by: Anthonios Partheniou --- samples/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements-test.txt b/samples/snippets/requirements-test.txt index ead482a5f..7d2834c42 100644 --- a/samples/snippets/requirements-test.txt +++ b/samples/snippets/requirements-test.txt @@ -1,2 +1,2 @@ -pytest==6.2.4 +pytest==6.2.5 google-cloud-storage==1.42.0 \ No newline at end of file From 1a7f455462b3b4885467acf2b5189c88c9d2ba79 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Thu, 2 Sep 2021 01:54:25 -0700 Subject: [PATCH 05/13] chore: group renovate prs (#114) This PR was generated using Autosynth. :rainbow: Synth log will be available here: https://source.cloud.google.com/results/invocations/25b83399-a873-4a0e-b9a9-28c73a203a7e/targets - [ ] To automatically regenerate this PR, check this box. (May take up to 24 hours.) --- CONTRIBUTING.rst | 6 +++--- renovate.json | 1 + synth.metadata | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 8a73ed9c7..e52913e04 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -113,9 +113,9 @@ Coding Style export GOOGLE_CLOUD_TESTING_BRANCH="main" By doing this, you are specifying the location of the most up-to-date - version of ``python-compute``. The the suggested remote name ``upstream`` - should point to the official ``googleapis`` checkout and the - the branch should be the main branch on that remote (``main``). + version of ``python-compute``. The + remote name ``upstream`` should point to the official ``googleapis`` + checkout and the branch should be the default branch on that remote (``main``). - This repository contains configuration for the `pre-commit `__ tool, which automates checking diff --git a/renovate.json b/renovate.json index 9fa8816fe..c21036d38 100644 --- a/renovate.json +++ b/renovate.json @@ -1,6 +1,7 @@ { "extends": [ "config:base", + "group:all", ":preserveSemverRanges", ":disableDependencyDashboard" ], diff --git a/synth.metadata b/synth.metadata index 917af3a46..889d07149 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,7 +4,7 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-compute.git", - "sha": "22a23d5fb7a5588be96a238be541817c641d068f" + "sha": "671bd6ac7c0311dde34a405c7607161ebab13cd5" } }, { From 631f0c1db319d5b1b94136696fb385b82e76a7de Mon Sep 17 00:00:00 2001 From: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Date: Tue, 7 Sep 2021 11:50:07 -0600 Subject: [PATCH 06/13] chore: reference main branch of google-cloud-python (#118) --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 506ef9846..efa504065 100644 --- a/README.rst +++ b/README.rst @@ -9,7 +9,7 @@ Python Client for Compute Engine - `Product Documentation`_ .. |alpha| image:: https://img.shields.io/badge/support-alpha-orange.svg - :target: https://github.com/googleapis/google-cloud-python/blob/master/README.rst#alpha-support + :target: https://github.com/googleapis/google-cloud-python/blob/main/README.rst#alpha-support .. |pypi| image:: https://img.shields.io/pypi/v/google-cloud-compute.svg :target: https://pypi.org/project/google-cloud-compute/ .. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-compute.svg @@ -79,4 +79,4 @@ Next Steps APIs that we cover. .. _Compute Engine API Product documentation: https://cloud.google.com/compute/ -.. _README: https://github.com/googleapis/google-cloud-python/blob/master/README.rst \ No newline at end of file +.. _README: https://github.com/googleapis/google-cloud-python/blob/main/README.rst \ No newline at end of file From 09852ed31c974e3a52ad1c813d7e7fa8125212e2 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 9 Sep 2021 16:43:17 +0200 Subject: [PATCH 07/13] chore(deps): update dependency google-cloud-storage to v1.42.1 (#119) --- samples/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements-test.txt b/samples/snippets/requirements-test.txt index 7d2834c42..394c07aa6 100644 --- a/samples/snippets/requirements-test.txt +++ b/samples/snippets/requirements-test.txt @@ -1,2 +1,2 @@ pytest==6.2.5 -google-cloud-storage==1.42.0 \ No newline at end of file +google-cloud-storage==1.42.1 \ No newline at end of file From 74d8d1568b743f7ef98754b0f5789b337c30509e Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Fri, 17 Sep 2021 08:19:07 -0700 Subject: [PATCH 08/13] chore: blacken samples noxfile template (#121) --- samples/snippets/noxfile.py | 44 +++++++++++++++++++++---------------- synth.metadata | 2 +- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/samples/snippets/noxfile.py b/samples/snippets/noxfile.py index e73436a15..b008613f0 100644 --- a/samples/snippets/noxfile.py +++ b/samples/snippets/noxfile.py @@ -39,17 +39,15 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - 'ignored_versions': [], - + "ignored_versions": [], # Old samples are opted out of enforcing Python type hints # All new samples should feature them - 'enforce_type_hints': False, - + "enforce_type_hints": False, # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string # to use your own Cloud project. - 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', # If you need to use a specific version of pip, # change pip_version_override to the string representation @@ -57,13 +55,13 @@ "pip_version_override": None, # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. - 'envs': {}, + "envs": {}, } try: # Ensure we can import noxfile_config in the project's directory. - sys.path.append('.') + sys.path.append(".") from noxfile_config import TEST_CONFIG_OVERRIDE except ImportError as e: print("No user noxfile_config found: detail: {}".format(e)) @@ -78,12 +76,12 @@ def get_pytest_env_vars() -> Dict[str, str]: ret = {} # Override the GCLOUD_PROJECT and the alias. - env_key = TEST_CONFIG['gcloud_project_env'] + env_key = TEST_CONFIG["gcloud_project_env"] # This should error out if not set. - ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] + ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] # Apply user supplied envs. - ret.update(TEST_CONFIG['envs']) + ret.update(TEST_CONFIG["envs"]) return ret @@ -92,11 +90,14 @@ def get_pytest_env_vars() -> Dict[str, str]: ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. -IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] +IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) -INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ("True", "true") +INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ( + "True", + "true", +) # # Style Checks # @@ -141,7 +142,7 @@ def _determine_local_import_names(start_dir: str) -> List[str]: @nox.session def lint(session: nox.sessions.Session) -> None: - if not TEST_CONFIG['enforce_type_hints']: + if not TEST_CONFIG["enforce_type_hints"]: session.install("flake8", "flake8-import-order") else: session.install("flake8", "flake8-import-order", "flake8-annotations") @@ -150,9 +151,11 @@ def lint(session: nox.sessions.Session) -> None: args = FLAKE8_COMMON_ARGS + [ "--application-import-names", ",".join(local_names), - "." + ".", ] session.run("flake8", *args) + + # # Black # @@ -165,6 +168,7 @@ def blacken(session: nox.sessions.Session) -> None: session.run("black", *python_files) + # # Sample Tests # @@ -173,7 +177,9 @@ def blacken(session: nox.sessions.Session) -> None: PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] -def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: +def _session_tests( + session: nox.sessions.Session, post_install: Callable = None +) -> None: if TEST_CONFIG["pip_version_override"]: pip_version = TEST_CONFIG["pip_version_override"] session.install(f"pip=={pip_version}") @@ -203,7 +209,7 @@ def _session_tests(session: nox.sessions.Session, post_install: Callable = None) # on travis where slow and flaky tests are excluded. # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html success_codes=[0, 5], - env=get_pytest_env_vars() + env=get_pytest_env_vars(), ) @@ -213,9 +219,9 @@ def py(session: nox.sessions.Session) -> None: if session.python in TESTED_VERSIONS: _session_tests(session) else: - session.skip("SKIPPED: {} tests are disabled for this sample.".format( - session.python - )) + session.skip( + "SKIPPED: {} tests are disabled for this sample.".format(session.python) + ) # diff --git a/synth.metadata b/synth.metadata index 889d07149..b11ba231f 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,7 +4,7 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-compute.git", - "sha": "671bd6ac7c0311dde34a405c7607161ebab13cd5" + "sha": "09852ed31c974e3a52ad1c813d7e7fa8125212e2" } }, { From a07d3f08fc8d6fc4d94a39401562fd954830dfa2 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Fri, 17 Sep 2021 17:48:09 +0200 Subject: [PATCH 09/13] chore(deps): update dependency google-cloud-storage to v1.42.2 (#120) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [google-cloud-storage](https://togithub.com/googleapis/python-storage) | `==1.42.1` -> `==1.42.2` | [![age](https://badges.renovateapi.com/packages/pypi/google-cloud-storage/1.42.2/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/google-cloud-storage/1.42.2/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/google-cloud-storage/1.42.2/compatibility-slim/1.42.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/google-cloud-storage/1.42.2/confidence-slim/1.42.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
googleapis/python-storage ### [`v1.42.2`](https://togithub.com/googleapis/python-storage/blob/master/CHANGELOG.md#​1422-httpswwwgithubcomgoogleapispython-storagecomparev1421v1422-2021-09-16) [Compare Source](https://togithub.com/googleapis/python-storage/compare/v1.42.1...v1.42.2)
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/python-compute). --- samples/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements-test.txt b/samples/snippets/requirements-test.txt index 394c07aa6..cec6ce6e2 100644 --- a/samples/snippets/requirements-test.txt +++ b/samples/snippets/requirements-test.txt @@ -1,2 +1,2 @@ pytest==6.2.5 -google-cloud-storage==1.42.1 \ No newline at end of file +google-cloud-storage==1.42.2 \ No newline at end of file From f32ec974efb9b23d785ea5d910cd270221629db4 Mon Sep 17 00:00:00 2001 From: Maciej Strzelczyk Date: Fri, 24 Sep 2021 14:34:02 +0200 Subject: [PATCH 10/13] chore(docs): Adding firewall samples. (#117) Co-authored-by: Dina Graves Portman Co-authored-by: Remigiusz Samborski --- samples/snippets/sample_firewall.py | 175 +++++++++++++++++++++++ samples/snippets/test_sample_firewall.py | 71 +++++++++ 2 files changed, 246 insertions(+) create mode 100644 samples/snippets/sample_firewall.py create mode 100644 samples/snippets/test_sample_firewall.py diff --git a/samples/snippets/sample_firewall.py b/samples/snippets/sample_firewall.py new file mode 100644 index 000000000..01a60c3d8 --- /dev/null +++ b/samples/snippets/sample_firewall.py @@ -0,0 +1,175 @@ +# Copyright 2021 Google LLC +# +# Licensed 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. + + +from typing import Iterable + +# [START compute_firewall_list] +# [START compute_firewall_create] +# [START compute_firewall_patch] +# [START compute_firewall_delete] +import google.cloud.compute_v1 as compute_v1 +# [END compute_firewall_delete] +# [END compute_firewall_patch] +# [END compute_firewall_create] +# [END compute_firewall_list] + + +# [START compute_firewall_list] +def list_firewall_rules(project_id: str) -> Iterable: + """ + Return a list of all the firewall rules in specified project. Also prints the + list of firewall names and their descriptions. + + Args: + project_id: project ID or project number of the Cloud project you want to use. + + Returns: + A flat list of all firewall rules defined for given project. + """ + firewall_client = compute_v1.FirewallsClient() + firewalls_list = firewall_client.list(project=project_id) + + for firewall in firewalls_list: + print(f" - {firewall.name}: {firewall.description}") + + return firewalls_list +# [END compute_firewall_list] + + +def print_firewall_rule(project_id: str, firewall_rule_name: str): + firewall_client = compute_v1.FirewallsClient() + print(firewall_client.get(project=project_id, firewall=firewall_rule_name)) + + +# [START compute_firewall_create] +def create_firewall_rule( + project_id: str, firewall_rule_name: str, network: str = "global/networks/default" +): + """ + Creates a simple firewall rule allowing for incoming HTTP and HTTPS access from the entire Internet. + + Args: + project_id: project ID or project number of the Cloud project you want to use. + firewall_rule_name: name of the rule that is created. + network: name of the network the rule will be applied to. Available name formats: + * https://www.googleapis.com/compute/v1/projects/{project_id}/global/networks/{network} + * projects/{project_id}/global/networks/{network} + * global/networks/{network} + """ + firewall_rule = compute_v1.Firewall() + firewall_rule.name = firewall_rule_name + firewall_rule.direction = compute_v1.Firewall.Direction.INGRESS + + tcp_80_443_allowed = compute_v1.Allowed() + tcp_80_443_allowed.I_p_protocol = "tcp" + tcp_80_443_allowed.ports = ["80", "443"] + + firewall_rule.allowed = [tcp_80_443_allowed] + firewall_rule.source_ranges = ["0.0.0.0/0"] + firewall_rule.network = network + firewall_rule.description = "Allowing TCP traffic on port 80 and 443 from Internet." + + # Note that the default value of priority for the firewall API is 1000. + # If you check the value of `firewall_rule.priority` at this point it + # will be equal to 0, however it is not treated as "set" by the library and thus + # the default will be applied to the new rule. If you want to create a rule that + # has priority == 0, you need to explicitly set it so: + + # firewall_rule.priority = 0 + + firewall_client = compute_v1.FirewallsClient() + op = firewall_client.insert(project=project_id, firewall_resource=firewall_rule) + + op_client = compute_v1.GlobalOperationsClient() + op_client.wait(project=project_id, operation=op.name) + + return +# [END compute_firewall_create] + + +# [START compute_firewall_patch] +def patch_firewall_priority(project_id: str, firewall_rule_name: str, priority: int): + """ + Modifies the priority of a given firewall rule. + + Args: + project_id: project ID or project number of the Cloud project you want to use. + firewall_rule_name: name of the rule you want to modify. + priority: the new priority to be set for the rule. + """ + firewall_rule = compute_v1.Firewall() + firewall_rule.priority = priority + + # The patch operation doesn't require the full definition of a Firewall object. It will only update + # the values that were set in it, in this case it will only change the priority. + firewall_client = compute_v1.FirewallsClient() + operation = firewall_client.patch( + project=project_id, firewall=firewall_rule_name, firewall_resource=firewall_rule + ) + + operation_client = compute_v1.GlobalOperationsClient() + operation_client.wait(project=project_id, operation=operation.name) + return +# [END compute_firewall_patch] + + +# [START compute_firewall_delete] +def delete_firewall_rule(project_id: str, firewall_rule_name: str): + """ + Deleted a firewall rule from the project. + + Args: + project_id: project ID or project number of the Cloud project you want to use. + firewall_rule_name: name of the firewall rule you want to delete. + """ + firewall_client = compute_v1.FirewallsClient() + operation = firewall_client.delete(project=project_id, firewall=firewall_rule_name) + + operation_client = compute_v1.GlobalOperationsClient() + operation_client.wait(project=project_id, operation=operation.name) + return +# [END compute_firewall_delete] + + +if __name__ == "__main__": + import google.auth + import google.auth.exceptions + + try: + default_project_id = google.auth.default()[1] + print(f"Using project {default_project_id}.") + except google.auth.exceptions.DefaultCredentialsError: + print( + "Please use `gcloud auth application-default login` " + "or set GOOGLE_APPLICATION_CREDENTIALS to use this script." + ) + else: + import uuid + + rule_name = "firewall-sample-" + uuid.uuid4().hex[:10] + print(f"Creating firewall rule {rule_name}...") + # The rule will be created with default priority of 1000. + create_firewall_rule(default_project_id, rule_name) + try: + print("Rule created:") + print_firewall_rule(default_project_id, rule_name) + print("Updating rule priority to 10...") + patch_firewall_priority(default_project_id, rule_name, 10) + print("Rule updated: ") + print_firewall_rule(default_project_id, rule_name) + print(f"Deleting rule {rule_name}...") + finally: + delete_firewall_rule(default_project_id, rule_name) + print("Done.") diff --git a/samples/snippets/test_sample_firewall.py b/samples/snippets/test_sample_firewall.py new file mode 100644 index 000000000..4e7384648 --- /dev/null +++ b/samples/snippets/test_sample_firewall.py @@ -0,0 +1,71 @@ +# Copyright 2021 Google LLC +# +# Licensed 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. +import time +import uuid + +import google.auth +from google.cloud import compute_v1 +import pytest + + +from sample_firewall import ( + create_firewall_rule, + delete_firewall_rule, + list_firewall_rules, + patch_firewall_priority, +) + +PROJECT = google.auth.default()[1] + + +@pytest.fixture +def firewall_rule(): + firewall_rule = compute_v1.Firewall() + firewall_rule.name = "firewall-sample-test" + uuid.uuid4().hex[:10] + firewall_rule.direction = compute_v1.Firewall.Direction.INGRESS + tcp_80_443_allowed = compute_v1.Allowed() + tcp_80_443_allowed.I_p_protocol = "tcp" + tcp_80_443_allowed.ports = ["80"] + firewall_rule.allowed = [tcp_80_443_allowed] + firewall_rule.source_ranges = ["0.0.0.0/0"] + firewall_rule.network = "global/networks/default" + firewall_rule.description = "Rule generated by Python sample test fixture." + + firewall_client = compute_v1.FirewallsClient() + op = firewall_client.insert(project=PROJECT, firewall_resource=firewall_rule) + + op_client = compute_v1.GlobalOperationsClient() + op_client.wait(project=PROJECT, operation=op.name) + + yield firewall_client.get(project=PROJECT, firewall=firewall_rule.name) + + op = firewall_client.delete(project=PROJECT, firewall=firewall_rule.name) + op_client.wait(project=PROJECT, operation=op.name) + + +def test_create_delete(): + rule_name = "firewall-sample-test-" + uuid.uuid4().hex[:10] + create_firewall_rule(PROJECT, rule_name) + assert any(rule.name == rule_name for rule in list_firewall_rules(PROJECT)) + delete_firewall_rule(PROJECT, rule_name) + assert all(rule.name != rule_name for rule in list_firewall_rules(PROJECT)) + + +def test_patch_rule(firewall_rule): + fw_client = compute_v1.FirewallsClient() + assert firewall_rule.priority == 1000 + patch_firewall_priority(PROJECT, firewall_rule.name, 500) + time.sleep(2) + updated_firewall_rule = fw_client.get(project=PROJECT, firewall=firewall_rule.name) + assert updated_firewall_rule.priority == 500 From 8e6293777e9197ed0ff795b3f74744c556777d07 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Wed, 29 Sep 2021 19:35:47 -0400 Subject: [PATCH 11/13] chore: add codeowner_team to repo-metadata.json (#116) --- .repo-metadata.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.repo-metadata.json b/.repo-metadata.json index d40bc1e22..d20a65ba2 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -9,5 +9,6 @@ "library_type": "GAPIC_AUTO", "repo": "googleapis/python-compute", "distribution_name": "google-cloud-compute", - "api_id": "compute.googleapis.com" + "api_id": "compute.googleapis.com", + "codeowner_team": "@googleapis/actools" } From 0517d833306c11f8bd9b32f5949251192cd91426 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Fri, 1 Oct 2021 12:21:09 +0200 Subject: [PATCH 12/13] chore(deps): update dependency google-cloud-storage to v1.42.3 (#122) --- samples/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements-test.txt b/samples/snippets/requirements-test.txt index cec6ce6e2..db0c32744 100644 --- a/samples/snippets/requirements-test.txt +++ b/samples/snippets/requirements-test.txt @@ -1,2 +1,2 @@ pytest==6.2.5 -google-cloud-storage==1.42.2 \ No newline at end of file +google-cloud-storage==1.42.3 \ No newline at end of file From 7a9e8324e08c46a93050908760b2b5aca054a863 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Mon, 4 Oct 2021 11:34:37 -0400 Subject: [PATCH 13/13] chore: add default_version to .repo-metadata.json (#124) * chore: add default_version and codeowner_team to .repo-metadata.json * update default_version --- .repo-metadata.json | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/.repo-metadata.json b/.repo-metadata.json index d20a65ba2..46cf133ca 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -1,14 +1,15 @@ { - "name": "compute", - "name_pretty": "Compute Engine", - "product_documentation": "https://cloud.google.com/compute/", - "client_documentation": "https://googleapis.dev/python/compute/latest", - "issue_tracker": "https://issuetracker.google.com/issues/new?component=187134&template=0", - "release_level": "alpha", - "language": "python", - "library_type": "GAPIC_AUTO", - "repo": "googleapis/python-compute", - "distribution_name": "google-cloud-compute", - "api_id": "compute.googleapis.com", - "codeowner_team": "@googleapis/actools" + "name": "compute", + "name_pretty": "Compute Engine", + "product_documentation": "https://cloud.google.com/compute/", + "client_documentation": "https://googleapis.dev/python/compute/latest", + "issue_tracker": "https://issuetracker.google.com/issues/new?component=187134&template=0", + "release_level": "alpha", + "language": "python", + "library_type": "GAPIC_AUTO", + "repo": "googleapis/python-compute", + "distribution_name": "google-cloud-compute", + "api_id": "compute.googleapis.com", + "codeowner_team": "@googleapis/actools", + "default_version": "v1" }