Skip to content

Commit

Permalink
Merge pull request #47 from tomdee/fix-packaging-2
Browse files Browse the repository at this point in the history
Fix packaging 2
  • Loading branch information
tomdee committed Jan 29, 2016
2 parents e875530 + 16ae2e2 commit 5327c2a
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 135 deletions.
40 changes: 14 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,29 @@ ipam: dist/calico-ipam

# Builds the Calico CNI plugin binary.
dist/calico: $(SRCFILES)
# Make sure the output directory exists.
mkdir -p dist
chmod 777 `pwd`/dist

# Build the CNI plugin
docker run \
-v `pwd`/dist:/code/dist \
-v `pwd`/calico_cni:/code \
calico/build pyinstaller calico_cni.py -a -F -s -n calico --clean
docker run --rm \
-v `pwd`:/code \
calico/build \
pyinstaller calico.py -ayF

# Makes the IPAM plugin.
dist/calico-ipam: $(SRCFILES)
mkdir -p dist
chmod 777 `pwd`/dist

# Build the CNI IPAM plugin
docker run \
-v `pwd`/dist:/code/dist \
-v `pwd`/calico_cni:/code \
calico/build pyinstaller ipam.py -a -F -s -n calico-ipam --clean
docker run --rm \
-v `pwd`:/code \
calico/build \
pyinstaller ipam.py -ayF -n calico-ipam

# Run the unit tests.
ut:
docker run --rm -v `pwd`/calico_cni:/code/calico_cni \
-v `pwd`/calico_cni/nose.cfg:/code/nose.cfg \
ut:
docker run --rm -v `pwd`:/code \
calico/test \
nosetests calico_cni/tests/unit -c nose.cfg
nosetests tests/unit -c nose.cfg

# Run the fv tests.
fv:
docker run --rm -v `pwd`/calico_cni:/code/calico_cni \
-v `pwd`/calico_cni/nose.cfg:/code/nose.cfg \
docker run --rm -v `pwd`:/code \
calico/test \
nosetests calico_cni/tests/fv -c nose.cfg
nosetests tests/fv -c nose.cfg

# Makes tests on Circle CI.
test-circle:
Expand All @@ -57,8 +46,7 @@ test-circle:
-v $(CIRCLE_TEST_REPORTS):/circle_output \
-e COVERALLS_REPO_TOKEN=$(COVERALLS_REPO_TOKEN) \
calico/test sh -c \
'>/dev/null 2>&1 & \
cd calico_cni; nosetests tests/unit tests/fv -c nose.cfg \
'nosetests tests -c nose.cfg \
--with-xunit --xunit-file=/circle_output/output.xml; RC=$$?;\
[[ ! -z "$$COVERALLS_REPO_TOKEN" ]] && coveralls || true; exit $$RC'

Expand Down
8 changes: 4 additions & 4 deletions calico_cni/calico_cni.py → calico.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
from pycalico.datastore import (DatastoreClient, ETCD_AUTHORITY_ENV,
ETCD_AUTHORITY_DEFAULT)
from pycalico.datastore_errors import MultipleEndpointsMatch
from util import (configure_logging, parse_cni_args, print_cni_error,
from calico_cni.util import (configure_logging, parse_cni_args, print_cni_error,
handle_datastore_error, CniError)

from container_engines import DefaultEngine, DockerEngine, get_container_engine
from constants import *
from calico_cni.container_engines import get_container_engine
from calico_cni.constants import *
from ipam import IpamPlugin
from policy_drivers import ApplyProfileError, get_policy_driver
from calico_cni.policy_drivers import ApplyProfileError, get_policy_driver

# Logging configuration.
LOG_FILENAME = "cni.log"
Expand Down
1 change: 0 additions & 1 deletion calico_cni/container_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import logging
import os
from util import configure_logging

from docker import Client
from docker.errors import APIError
Expand Down
9 changes: 4 additions & 5 deletions calico_cni/policy_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
# limitations under the License.

import os
import re
import sys
import json
import logging
import requests
from util import configure_logging, print_cni_error
from calico_cni.util import print_cni_error
from pycalico.datastore import DatastoreClient
from pycalico.datastore_datatypes import Rule, Rules
from pycalico.datastore_errors import MultipleEndpointsMatch
from pycalico.util import validate_characters

from constants import *
from policy_parser import PolicyParser
from calico_cni.constants import *
import calico_cni.policy_parser

# Use the same logger as calico_cni.
_log = logging.getLogger("calico_cni")
Expand Down Expand Up @@ -158,7 +157,7 @@ class KubernetesAnnotationDriver(DefaultPolicyDriver):
def __init__(self, pod_name, namespace, auth_token, api_root):
self.pod_name = pod_name
self.namespace = namespace
self.policy_parser = PolicyParser(namespace)
self.policy_parser = calico_cni.policy_parser.PolicyParser(namespace)
self.auth_token = auth_token
self.api_root = api_root
self.profile_name = "%s_%s" % (namespace, pod_name)
Expand Down
1 change: 0 additions & 1 deletion calico_cni/policy_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import docopt
import logging
import re
from netaddr import IPNetwork, AddrFormatError
from pycalico.datastore_datatypes import Rule

_log = logging.getLogger(__name__)
Expand Down
3 changes: 1 addition & 2 deletions calico_cni/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import errno
import os
import json
import sys
import logging
from cloghandler import ConcurrentRotatingFileHandler
from constants import *
from calico_cni.constants import *

from pycalico.datastore_errors import DataStoreError

Expand Down
6 changes: 3 additions & 3 deletions calico_cni/ipam.py → ipam.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from netaddr import IPNetwork

from pycalico.ipam import IPAMClient
from util import configure_logging, print_cni_error
from constants import *
from util import CniError
from calico_cni.util import configure_logging, print_cni_error
from calico_cni.constants import *
from calico_cni.util import CniError


# Logging config.
Expand Down
File renamed without changes.
Empty file added tests/__init__.py
Empty file.
Empty file added tests/fv/__init__.py
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys
import json
import unittest
from mock import patch, MagicMock, call, ANY
from netaddr import IPAddress, IPNetwork
from subprocess32 import CalledProcessError, Popen, PIPE
from nose.tools import assert_equal, assert_true, assert_false, assert_raises

from mock import patch, MagicMock, ANY
from netaddr import IPNetwork
from nose.tools import assert_equal, assert_true, assert_false, assert_raises
from pycalico.datastore import DatastoreClient
from pycalico.datastore_datatypes import Endpoint, Rule, Rules
from pycalico.datastore_errors import DataStoreError
from pycalico.datastore_datatypes import Rule, Rules
from pycalico.datastore_errors import DataStoreError

from calico_cni import calico_cni, container_engines, ipam
from calico_cni.calico_cni import CniPlugin
import calico
import ipam
from calico_cni import container_engines
from calico_cni.constants import *
from calico_cni.policy_drivers import (DefaultPolicyDriver,
KubernetesDefaultPolicyDriver, KubernetesAnnotationDriver)
from calico_cni.container_engines import DockerEngine
from calico_cni.policy_drivers import (DefaultPolicyDriver,
KubernetesDefaultPolicyDriver, KubernetesAnnotationDriver)


class CniPluginFvTest(unittest.TestCase):
Expand Down Expand Up @@ -58,17 +56,17 @@ def setUp(self):
self.client = MagicMock(spec=DatastoreClient)

# Setup module mocks.
self.popen = calico_cni.Popen
self.popen = calico.Popen
self.m_popen = MagicMock(spec=self.popen)
calico_cni.Popen = self.m_popen
calico.Popen = self.m_popen

self.os = calico_cni.os
self.os = calico.os
self.m_os = MagicMock(spec=self.os)
calico_cni.os = self.m_os
calico.os = self.m_os

self.netns = calico_cni.netns
self.netns = calico.netns
self.m_netns = MagicMock(spec=self.netns)
calico_cni.netns = self.m_netns
calico.netns = self.m_netns

self.docker_client = container_engines.Client
self.m_docker_client = MagicMock(self.docker_client)
Expand All @@ -80,9 +78,9 @@ def setUp(self):

def tearDown(self):
# Reset module mocks.
calico_cni.Popen = self.m_popen
calico_cni.os = self.os
calico_cni.netns = self.m_netns
calico.Popen = self.m_popen
calico.os = self.os
calico.netns = self.m_netns
container_engines.Client = self.docker_client
ipam.IPAMClient = self.ipam_plugin_client

Expand All @@ -106,7 +104,7 @@ def create_plugin(self):
}

# Create the CniPlugin to test.
plugin = CniPlugin(self.network_config, self.env)
plugin = calico.CniPlugin(self.network_config, self.env)

# Mock out the datastore client.
plugin._client = self.client
Expand Down
Empty file added tests/unit/__init__.py
Empty file.
Loading

0 comments on commit 5327c2a

Please sign in to comment.