def _test__convert_annotations(self, method, calls): self.cmd.k8s.annotate = mock.Mock() ann_objs = [ ('foo', vif.PodState(default_vif=vif.VIFMacvlanNested(vif_name='foo'))), ('bar', vif.VIFMacvlanNested(vif_name='bar')), ] ann_objs = [(name, jsonutils.dumps(ann.obj_to_primitive())) for name, ann in ann_objs] pods = { 'items': [ { 'metadata': { 'annotations': { constants.K8S_ANNOTATION_VIF: ann }, 'selfLink': name, 'resourceVersion': 1, } } for name, ann in ann_objs ] } self.cmd.k8s = mock.Mock(get=mock.Mock(return_value=pods)) method() for args in calls: self.cmd.k8s.annotate.assert_any_call(*args)
def test__check_annotations_failure(self): ann_objs = [ vif.PodState(default_vif=vif.VIFMacvlanNested(vif_name='foo')), vif.VIFMacvlanNested(vif_name='bar'), ] ann_objs = [jsonutils.dumps(ann.obj_to_primitive()) for ann in ann_objs] self._test__check_annotations(ann_objs, 2)
def test__check_annotations_malformed_and_old(self): ann_objs = [ vif.PodState(default_vif=vif.VIFMacvlanNested(vif_name='foo')), vif.VIFMacvlanNested(vif_name='bar'), ] ann_objs = [jsonutils.dumps(ann.obj_to_primitive()) for ann in ann_objs] ann_objs.append('{}') self._test__check_annotations(ann_objs, 2)
def test__get_annotation_existing(self): mock_obj = vif.PodState( default_vif=vif.VIFMacvlanNested(vif_name='foo')) pod = { 'metadata': { 'annotations': { constants.K8S_ANNOTATION_VIF: jsonutils.dumps( mock_obj.obj_to_primitive()) } } } obj = self.cmd._get_annotation(pod) self.assertEqual(mock_obj, obj)
def neutron_to_osvif_vif_nested_macvlan(neutron_port, subnets): """Converts Neutron port to VIF object for MACVLAN nested containers. :param neutron_port: dict containing port information as returned by neutron client's 'show_port' :param subnets: subnet mapping as returned by PodSubnetsDriver.get_subnets :return: kuryr-k8s native VIF object for MACVLAN nested """ details = neutron_port.get('binding:vif_details', {}) return k_vif.VIFMacvlanNested( id=neutron_port['id'], address=neutron_port['mac_address'], network=_make_vif_network(neutron_port, subnets), has_traffic_filtering=details.get('port_filter', False), preserve_on_delete=False, active=_is_port_active(neutron_port), plugin=const.K8S_OS_VIF_NOOP_PLUGIN, vif_name=_get_vif_name(neutron_port))