nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: metal3-io/baremetal-operator
Pull request #965 (2021-09-03 06:55:52)

Enable detach annotation for ready nodes


Patch:
diff --git a/controllers/metal3.io/host_state_machine.go b/controllers/metal3.io/host_state_machine.go
index 338bdb4b..03a76f6d 100644
--- a/controllers/metal3.io/host_state_machine.go
+++ b/controllers/metal3.io/host_state_machine.go
@@ -256,7 +256,7 @@ func (hsm *hostStateMachine) checkDetachedHost(info *reconcileInfo) (result acti
 	if hasDetachedAnnotation(hsm.Host) {
 		// Only allow detaching hosts in Provisioned/ExternallyProvisioned states
 		switch info.host.Status.Provisioning.State {
-		case metal3v1alpha1.StateProvisioned, metal3v1alpha1.StateExternallyProvisioned:
+		case metal3v1alpha1.StateProvisioned, metal3v1alpha1.StateExternallyProvisioned, metal3v1alpha1.StateReady:
 			return hsm.Reconciler.detachHost(hsm.Provisioner, info)
 		}
 	}


Test patch:
diff --git a/controllers/metal3.io/host_state_machine_test.go b/controllers/metal3.io/host_state_machine_test.go
index 70ac5a90..88666edf 100644
--- a/controllers/metal3.io/host_state_machine_test.go
+++ b/controllers/metal3.io/host_state_machine_test.go
@@ -318,10 +318,28 @@ func TestDetach(t *testing.T) {
 			ExpectedOperationalStatus: metal3v1alpha1.OperationalStatusOK,
 			ExpectedState:             metal3v1alpha1.StateReady,
 		},
+		{
+			Scenario:                  "DetachReadyHost",
+			Host:                      host(metal3v1alpha1.StateReady).SetImageURL("").SetStatusPoweredOn(false).build(),
+			HasDetachedAnnotation:     true,
+			ExpectedDetach:            true,
+			ExpectedDirty:             true,
+			ExpectedOperationalStatus: metal3v1alpha1.OperationalStatusDetached,
+			ExpectedState:             metal3v1alpha1.StateReady,
+		},
+		{
+			Scenario:                  "AttachReadyHost",
+			Host:                      host(metal3v1alpha1.StateReady).SetImageURL("").SetStatusPoweredOn(false).build(),
+			HasDetachedAnnotation:     false,
+			ExpectedDetach:            false,
+			ExpectedDirty:             true,
+			ExpectedOperationalStatus: metal3v1alpha1.OperationalStatusOK,
+			ExpectedState:             metal3v1alpha1.StateReady,
+		},
 		{
 			Scenario:                  "ReadyHost",
 			Host:                      host(metal3v1alpha1.StateReady).build(),
-			HasDetachedAnnotation:     true,
+			HasDetachedAnnotation:     false,
 			ExpectedDetach:            false,
 			ExpectedDirty:             true,
 			ExpectedOperationalStatus: metal3v1alpha1.OperationalStatusOK,
Repository: googleapis/python-api-core
Pull request #20 (2020-03-31 20:33:29)

feat: [CBT-6 helper] Exposing Retry._deadline as a property
The suggested way of fixing cbt-6 involves propagating the value of a private member of the Retry class down to gRPC wrapper. The proposed changes are necessary to avoid the associated linting errors.

Fixes [#6](https://github.com/googleapis/python-bigtable/issues/6)


mf2199: @kolea2 Friendly ping.

Patch:
diff --git a/google/api_core/retry.py b/google/api_core/retry.py
index a1d1f18..446d43c 100644
--- a/google/api_core/retry.py
+++ b/google/api_core/retry.py
@@ -288,6 +288,10 @@ class Retry(object):
 
         return retry_wrapped_func
 
+    @property
+    def deadline(self):
+        return self._deadline
+
     def with_deadline(self, deadline):
         """Return a copy of this retry with the given deadline.
 


Test patch:
diff --git a/tests/unit/test_retry.py b/tests/unit/test_retry.py
index be0c688..a0160e9 100644
--- a/tests/unit/test_retry.py
+++ b/tests/unit/test_retry.py
@@ -162,6 +162,7 @@ class TestRetry(object):
         assert retry_._multiplier == 2
         assert retry_._deadline == 120
         assert retry_._on_error is None
+        assert retry_.deadline == 120
 
     def test_constructor_options(self):
         _some_function = mock.Mock()
Repository: googleapis/python-api-core
Pull request #159 (2021-03-24 23:24:05)

fix: skip empty policy bindings in `len()` and `iter()`
Exclude empty policy bindings (bindings with no members) in
`Policy.__iter__()` and `Policy.__len__()`

Follow up to #155 



Patch:
diff --git a/google/api_core/iam.py b/google/api_core/iam.py
index d83cbf3..c498c68 100644
--- a/google/api_core/iam.py
+++ b/google/api_core/iam.py
@@ -125,18 +125,22 @@ class Policy(collections_abc.MutableMapping):
 
     def __iter__(self):
         self.__check_version__()
-        return (binding["role"] for binding in self._bindings)
+        # Exclude bindings with no members
+        return (binding["role"] for binding in self._bindings if binding["members"])
 
     def __len__(self):
         self.__check_version__()
-        return len(self._bindings)
+        # Exclude bindings with no members
+        return len(list(self.__iter__()))
 
     def __getitem__(self, key):
         self.__check_version__()
         for b in self._bindings:
             if b["role"] == key:
                 return b["members"]
-        # binding does not yet exist, create one
+        # If the binding does not yet exist, create one
+        # NOTE: This will create bindings with no members
+        # which are ignored by __iter__ and __len__
         new_binding = {"role": key, "members": set()}
         self._bindings.append(new_binding)
         return new_binding["members"]


Test patch:
diff --git a/tests/unit/test_iam.py b/tests/unit/test_iam.py
index f9771f0..0da9b23 100644
--- a/tests/unit/test_iam.py
+++ b/tests/unit/test_iam.py
@@ -32,11 +32,11 @@ class TestPolicy:
         policy = self._make_one()
         assert policy.etag is None
         assert policy.version is None
-        assert len(policy) == 0
-        assert dict(policy) == {}
         assert policy.owners == empty
         assert policy.editors == empty
         assert policy.viewers == empty
+        assert len(policy) == 0
+        assert dict(policy) == {}
 
     def test_ctor_explicit(self):
         VERSION = 1
@@ -45,11 +45,11 @@ class TestPolicy:
         policy = self._make_one(ETAG, VERSION)
         assert policy.etag == ETAG
         assert policy.version == VERSION
-        assert len(policy) == 0
-        assert dict(policy) == {}
         assert policy.owners == empty
         assert policy.editors == empty
         assert policy.viewers == empty
+        assert len(policy) == 0
+        assert dict(policy) == {}
 
     def test___getitem___miss(self):
         policy = self._make_one()
@@ -301,10 +301,10 @@ class TestPolicy:
         policy = klass.from_api_repr(RESOURCE)
         assert policy.etag == "ACAB"
         assert policy.version is None
-        assert dict(policy) == {}
         assert policy.owners == empty
         assert policy.editors == empty
         assert policy.viewers == empty
+        assert dict(policy) == {}
 
     def test_from_api_repr_complete(self):
         from google.api_core.iam import OWNER_ROLE, EDITOR_ROLE, VIEWER_ROLE
Repository: googleapis/python-api-core
Pull request #177 (2021-04-29 09:01:41)

chore: add SECURITY.md
chore: add SECURITY.md


Patch:
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 0000000..8b58ae9
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,7 @@
+# Security Policy
+
+To report a security issue, please use [g.co/vulnz](https://g.co/vulnz).
+
+The Google Security Team will respond within 5 working days of your report on g.co/vulnz.
+
+We use g.co/vulnz for our intake, and do coordination and disclosure here using GitHub Security Advisory to privately discuss and fix the issue.
diff --git a/google/api_core/retry.py b/google/api_core/retry.py
index 43e4f07..f0f23bc 100644
--- a/google/api_core/retry.py
+++ b/google/api_core/retry.py
@@ -62,11 +62,13 @@ import logging
 import random
 import time
 
+import requests.exceptions
 import six
 
 from google.api_core import datetime_helpers
 from google.api_core import exceptions
 from google.api_core import general_helpers
+from google.auth import exceptions as auth_exceptions
 
 _LOGGER = logging.getLogger(__name__)
 _DEFAULT_INITIAL_DELAY = 1.0  # seconds
@@ -101,6 +103,8 @@ if_transient_error = if_exception_type(
     exceptions.InternalServerError,
     exceptions.TooManyRequests,
     exceptions.ServiceUnavailable,
+    requests.exceptions.ConnectionError,
+    auth_exceptions.TransportError,
 )
 """A predicate that checks if an exception is a transient API error.
 


Test patch:
diff --git a/tests/unit/test_retry.py b/tests/unit/test_retry.py
index 4c2e457..ce8f417 100644
--- a/tests/unit/test_retry.py
+++ b/tests/unit/test_retry.py
@@ -18,9 +18,11 @@ import re
 
 import mock
 import pytest
+import requests.exceptions
 
 from google.api_core import exceptions
 from google.api_core import retry
+from google.auth import exceptions as auth_exceptions
 
 
 def test_if_exception_type():
@@ -42,6 +44,8 @@ def test_if_transient_error():
     assert retry.if_transient_error(exceptions.InternalServerError(""))
     assert retry.if_transient_error(exceptions.TooManyRequests(""))
     assert retry.if_transient_error(exceptions.ServiceUnavailable(""))
+    assert retry.if_transient_error(requests.exceptions.ConnectionError(""))
+    assert retry.if_transient_error(auth_exceptions.TransportError(""))
     assert not retry.if_transient_error(exceptions.InvalidArgument(""))