def testUpdateTraffic_Succeed(self): mock_output = testdata.SERVICE_STRING svc_name = 'bar' command = """kuberun core services update-traffic {} --cluster foo --cluster-location us-central1 --to-latest""".format(svc_name) self.mock_bin_exec.return_value = bin_ops.BinaryBackedOperation.OperationResult( command, output=mock_output) result = self.Run(command) self.AssertExecuteCalledOnce(command_args=[ 'core', 'services', 'update-traffic', svc_name, '--cluster', 'foo', '--cluster-location', 'us-central1', '--to-latest' ]) expected_result = traffic_pair.GetTrafficTargetPairs( spec_traffic={ 'hello-00001-loq': [ traffic.TrafficTarget({ 'revisionName': 'hello-00001-loq', 'percent': 100, 'latestRevision': False, 'tag': 'tag1', 'url': 'hello-00001-loq.service.example.com' }) ] }, status_traffic={ 'hello-00001-loq': [ traffic.TrafficTarget({ 'revisionName': 'hello-00001-loq', 'percent': 100, 'latestRevision': False, 'tag': 'tag1', 'url': 'hello-00001-loq.service.example.com' }) ] }, latest_ready_revision_name='hello-00001-loq', service_url='http://hello.default.example.com') self.assertEqual(1, len(result)) self.assertEqual(expected_result[0], result[0])
def testGetKey_notLatest(self): self.assertEqual( traffic.GetKey( traffic.TrafficTarget({ "revisionName": "rev1", "latestRevision": False })), "rev1")
def testGetKey_latest(self): self.assertEqual( traffic.GetKey( traffic.TrafficTarget({ "revisionName": "rev1", "latestRevision": True })), "LATEST")
def _TrafficDict(traffic_list): if traffic_list: return { traffic.GetKey(tt): [tt] for tt in (traffic.TrafficTarget(x) for x in traffic_list) } else: return dict()
def status_traffic(self): if 'traffic' in self._props['status']: return { traffic.GetKey(tt): [tt] for tt in (traffic.TrafficTarget(x) for x in self._props['status']['traffic']) } else: return dict()