Skip to content

Commit

Permalink
Fix existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
caseydavenport committed May 22, 2016
1 parent a51a6f5 commit 937a5dd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ deploy-rkt: dist/calicoctl
ut: update-version
docker run --rm -v `pwd`:/code \
calico/test \
nosetests tests/unit -c nose.cfg
sh -c "pip install pykube && nosetests tests/unit -c nose.cfg"

# Run the fv tests.
fv: update-version
docker run --rm -v `pwd`:/code \
calico/test \
nosetests tests/fv -c nose.cfg
sh -c "pip install pykube && nosetests tests/fv -c nose.cfg"

# Makes tests on Circle CI.
test-circle: update-version dist/calico dist/calico-ipam
Expand All @@ -63,7 +63,8 @@ test-circle: update-version dist/calico dist/calico-ipam
-v $(CIRCLE_TEST_REPORTS):/circle_output \
-e COVERALLS_REPO_TOKEN=$(COVERALLS_REPO_TOKEN) \
calico/test sh -c \
'nosetests tests -c nose.cfg \
'pip install pykube && \
nosetests tests -c nose.cfg \
--with-xunit --xunit-file=/circle_output/output.xml; RC=$$?;\
[[ ! -z "$$COVERALLS_REPO_TOKEN" ]] && coveralls || true; exit $$RC'

Expand Down
7 changes: 5 additions & 2 deletions calico.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ def _call_ipam_plugin(self, env):
_log.debug("Calling host-local IPAM plugin")
code, response = self._call_binary_ipam_plugin(env)
else:
# Using some other IPAM plugin - call it.
_log.debug("Using binary plugin")
code, response = self._call_binary_ipam_plugin(env)

Expand All @@ -486,7 +487,8 @@ def _get_kubernetes_pod_cidr(self):
pod_cidr = f.read().strip()
_log.debug("Loaded podCidr from disk: %s", pod_cidr)
else:
_log.info("Getting node.spec.podCidr from API")
_log.info("Getting node.spec.podCidr from API, kubeconfig: %s",
self.kubeconfig_path)
if not self.kubeconfig_path:
# Fow now, kubeconfig is the only supported auth method.
print_cni_error(ERR_CODE_GENERIC, "Missing kubeconfig",
Expand All @@ -504,7 +506,8 @@ def _get_kubernetes_pod_cidr(self):
break
if not node:
raise KeyError("Unable to find node in API: %s", self.k8s_node_name)
_log.info("Found node: %s: ", node.obj)
_log.debug("Found node %s: %s: ", node.obj["metadata"]["name"],
node.obj["spec"])
except Exception:
print_cni_error(ERR_CODE_GENERIC, "Error querying Kubernetes API",
"Failed to get podCidr from Kubernetes API")
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/test_policy_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def setUp(self):
"policy": {}
}
self.driver = KubernetesAnnotationDriver(self.pod_name, self.namespace,
self.auth_token, self.api_root, None, None, None)
self.auth_token, self.api_root, None, None, None, None)
assert_equal(self.driver.profile_name, self.profile_name)

# Mock the DatastoreClient
Expand All @@ -161,7 +161,7 @@ def test_generate_rules_kube_system(self, m_get_pod):
# Generate rules
rules = self.driver.generate_rules()

# Assert correct. Should allow all.
# Assert correct. Should allow all.
expected = Rules(id=self.profile_name,
inbound_rules=[Rule(action="allow")],
outbound_rules=[Rule(action="allow")])
Expand All @@ -187,7 +187,7 @@ def test_generate_rules_annotations(self, m_get_pod):
# Generate rules
rules = self.driver.generate_rules()

# Assert correct. Should allow all.
# Assert correct. Should allow all.
expected = Rules(id=self.profile_name,
inbound_rules=[Rule(action="allow", protocol="tcp")],
outbound_rules=[Rule(action="allow")])
Expand All @@ -202,7 +202,7 @@ def test_generate_rules_parse_error(self, m_get_pod):

# Mock to raise error
self.driver.policy_parser = MagicMock(spec=self.driver.policy_parser)
self.driver.policy_parser.parse_line.side_effect = ValueError
self.driver.policy_parser.parse_line.side_effect = ValueError

# Generate rules
assert_raises(ApplyProfileError, self.driver.generate_rules)
Expand All @@ -211,7 +211,7 @@ def test_generate_tags(self):
# Mock get_metadata to return labels.
labels = {"key": "value"}
self.driver._get_metadata = MagicMock(spec=self.driver._get_metadata)
self.driver._get_metadata.return_value = labels
self.driver._get_metadata.return_value = labels

# Call
tags = self.driver.generate_tags()
Expand Down Expand Up @@ -353,7 +353,7 @@ def test_get_api_pod_parse_error(self, m_json_load, m_session):
# Set up mock objects
self.driver.auth_token = 'TOKEN'

m_json_load.side_effect = TypeError
m_json_load.side_effect = TypeError

get_obj = Mock()
get_obj.status_code = 200
Expand Down Expand Up @@ -388,7 +388,7 @@ def setUp(self):
self.network_name = "net-name"
self.namespace = "default"
self.driver = KubernetesPolicyDriver(self.network_name, self.namespace,
None, None, None, None, None)
None, None, None, None, None, None)

# Mock the DatastoreClient
self.client = MagicMock(spec=DatastoreClient)
Expand Down Expand Up @@ -417,7 +417,7 @@ def test_remove_profile(self):
self.driver.remove_profile()


class GetPolicyDriverTest(unittest.TestCase):
class GetPolicyDriverTest(unittest.TestCase):

def test_get_policy_driver_default_k8s(self):
cni_plugin = Mock(spec=CniPlugin)
Expand Down

0 comments on commit 937a5dd

Please sign in to comment.