13
13
# See the License for the specific language governing permissions and
14
14
# limitations under the License.
15
15
16
+ import collections
16
17
import copy
17
18
from unittest import mock
18
19
@@ -460,6 +461,7 @@ def __init__(self):
460
461
self .activated_bindings = set ()
461
462
self .conf = mock .Mock ()
462
463
self .conf .host = 'host1'
464
+ self .network_ports = collections .defaultdict (list )
463
465
464
466
465
467
class TestSriovNicSwitchRpcCallbacks (base .BaseTestCase ):
@@ -528,6 +530,12 @@ def test_binding_activate(self):
528
530
}
529
531
kwargs = self ._create_fake_bindings (fake_port , self .agent .conf .host )
530
532
kwargs ['context' ] = self .context
533
+
534
+ self .agent .network_ports ['network_id' ].append ({
535
+ 'port_id' : fake_port ['id' ],
536
+ 'device' : 'fake_device'
537
+ })
538
+
531
539
self .sriov_rpc_callback .binding_activate (** kwargs )
532
540
# Assert agent.activated_binding set contains the new binding
533
541
self .assertIn ((fake_port ['mac_address' ],
@@ -538,10 +546,32 @@ def test_binding_activate_no_host(self):
538
546
fake_port = self ._create_fake_port ()
539
547
kwargs = self ._create_fake_bindings (fake_port , 'other-host' )
540
548
kwargs ['context' ] = self .context
549
+
550
+ self .agent .network_ports [self .agent .conf .host ].append ({
551
+ 'port_id' : fake_port ['id' ],
552
+ 'device' : 'fake_device'
553
+ })
554
+
541
555
self .sriov_rpc_callback .binding_activate (** kwargs )
542
556
# Assert no bindings were added
543
557
self .assertEqual (set (), self .agent .activated_bindings )
544
558
559
+ def test_binding_activate_port_not_in_network (self ):
560
+ fake_port = self ._create_fake_port ()
561
+ kwargs = self ._create_fake_bindings (fake_port , self .agent .conf .host )
562
+ kwargs ['context' ] = self .context
563
+
564
+ self .agent .network_ports ['network_id' ] = []
565
+
566
+ with mock .patch .object (sriov_nic_agent .LOG ,
567
+ 'warning' ) as mock_warning :
568
+ self .sriov_rpc_callback .binding_activate (** kwargs )
569
+ # Check that the warning message was logged
570
+ expected_msg = (
571
+ "This port is not SRIOV, skip binding for port %s."
572
+ )
573
+ mock_warning .assert_called_once_with (expected_msg , fake_port ['id' ])
574
+
545
575
def test_binding_deactivate (self ):
546
576
# binding_deactivate() basically does nothing
547
577
# call it with both the agent's host and other host to cover
0 commit comments