VOL-572: Integration testing with Kubernetes

* Updated test_voltha_alarm_events to run in the single-node Kubernetes environment, as well
well as in docker-compose. Removed the steps to run ponsim from the README descriptions for
test_voltha_alarm_events and test_voltha_alarm_filters; these tests create simulated_olt devices,
not ponsim_olt devices.

* Updated test_voltha_xpon to run in the single-node Kubernetes environment, as well as
in docker-compose. The test takes about 10 times longer to run in Kubernetes; the reason
why is currently unknown.

Change-Id: I751cf1a84a48af1123e340e739263f5b58d39a0e
diff --git a/tests/itests/README.md b/tests/itests/README.md
index 44e2571..ebbba5a 100644
--- a/tests/itests/README.md
+++ b/tests/itests/README.md
@@ -188,29 +188,38 @@
 The test will first verify that the kafka alarm topic exists.  It will then create a simulated_olt
 device and verify that alarms are generated by the device.
 
-First start the Voltha ensemble:
+To run the test in the docker-compose environment,
+start the Voltha ensemble and then run the test:
 ```
 cd /cord/incubator/voltha
 . ./env.sh
+docker-compose -f compose/docker-compose-system-test.yml down
 docker-compose -f compose/docker-compose-system-test.yml up -d
-```    
-Then start PONSIM in a separate window:
-``` 
-sudo -s
-. ./env.sh
-./ponsim/main.py -v -o 4 -a -f 5
-``` 
-Enable port forwarding
-``` 
-sudo -s
-echo 8 > /sys/class/net/ponmgmt/bridge/group_fwd_mask            
-``` 
-Run the test:
-``` 
-cd /cord/incubator/voltha
-. ./env.sh
 nosetests -s tests/itests/voltha/test_voltha_alarm_events.py
-```  
+```
+
+To run the test in a single-node Kubernetes environment (see document voltha/BUILD.md),
+start the Voltha ensemble:
+```
+./tests/itests/env/voltha-k8s-stop.sh
+./tests/itests/env/voltha-k8s-start.sh
+```
+Wait until all the Voltha pods are in the Running state and take note of
+Kafka's pod IP address. Enter the following line into the /etc/hosts file:
+```
+<kafka-pod-IP-address> kafka-0.kafka.voltha.svc.cluster.local
+```
+The test invokes the kafkacat client which complains that it can't resolve
+kafka-0.kafka.voltha.svc.cluster.local. This domain name is only accessible
+from within pods deployed to the Kubernetes cluster. The test, however, runs
+outside the cluster. There may be another solution to this problem, but for
+now, this may have to do. Once the test is fully automated, /etc/hosts can
+be modified by the test itself.
+
+To run the test:
+```
+nosetests -s tests/itests/voltha/test_voltha_alarm_events.py --tc-file=tests/itests/env/k8s-consul.ini
+```
 
 * **Voltha_alarm_filters**: This test exercises the alarm event filtering mechanism
 
@@ -218,29 +227,14 @@
 along with a filter against one of the devices.  The test will validate that alarms are received
 for the unfiltered device and alarms will be suppressed for the filtered device.
 
-First start the Voltha ensemble:
+After starting the Voltha ensemble, run the test:
 ```
 cd /cord/incubator/voltha
 . ./env.sh
+docker-compose -f compose/docker-compose-system-test.yml down
 docker-compose -f compose/docker-compose-system-test.yml up -d
-```    
-Then start PONSIM in a separate window:
-``` 
-sudo -s
-. ./env.sh
-./ponsim/main.py -v -o 4 -a -f 5
-``` 
-Enable port forwarding
-``` 
-sudo -s
-echo 8 > /sys/class/net/ponmgmt/bridge/group_fwd_mask            
-``` 
-Run the test:
-``` 
-cd /cord/incubator/voltha
-. ./env.sh
 nosetests -s tests/itests/voltha/test_voltha_alarm_filters.py
-```  
+```
 
 * **Dispatcher**:  This test exercises the requests forwarding via the Global 
 handler.
diff --git a/tests/itests/env/voltha-k8s-start.sh b/tests/itests/env/voltha-k8s-start.sh
index 0a1653a..93de7cc 100755
--- a/tests/itests/env/voltha-k8s-start.sh
+++ b/tests/itests/env/voltha-k8s-start.sh
@@ -2,9 +2,12 @@
 
 kubectl apply -f k8s/namespace.yml
 kubectl apply -f k8s/single-node/consul.yml
+kubectl apply -f k8s/single-node/zookeeper.yml
+kubectl apply -f k8s/single-node/kafka.yml
 kubectl apply -f k8s/single-node/fluentd.yml
 
 kubectl apply -f k8s/single-node/vcore_for_consul.yml
 kubectl apply -f k8s/envoy_for_consul.yml
 kubectl apply -f k8s/single-node/vcli.yml
 kubectl apply -f k8s/single-node/ofagent.yml
+kubectl apply -f k8s/single-node/netconf.yml
diff --git a/tests/itests/env/voltha-k8s-stop.sh b/tests/itests/env/voltha-k8s-stop.sh
index ee978f5..58f9063 100755
--- a/tests/itests/env/voltha-k8s-stop.sh
+++ b/tests/itests/env/voltha-k8s-stop.sh
@@ -1,10 +1,13 @@
 #!/bin/bash
 
-kubectl delete -f k8s/single-node/consul.yml
-kubectl delete -f k8s/single-node/fluentd.yml
-
-kubectl delete -f k8s/single-node/vcore_for_consul.yml
-kubectl delete -f k8s/envoy_for_consul.yml
-kubectl delete -f k8s/single-node/vcli.yml
+kubectl delete -f k8s/single-node/netconf.yml
 kubectl delete -f k8s/single-node/ofagent.yml
+kubectl delete -f k8s/single-node/vcli.yml
+kubectl delete -f k8s/envoy_for_consul.yml
+kubectl delete -f k8s/single-node/vcore_for_consul.yml
+
+kubectl delete -f k8s/single-node/fluentd.yml
+kubectl delete -f k8s/single-node/kafka.yml
+kubectl delete -f k8s/single-node/zookeeper.yml
+kubectl delete -f k8s/single-node/consul.yml
 kubectl delete -f k8s/namespace.yml
diff --git a/tests/itests/voltha/test_voltha_alarm_events.py b/tests/itests/voltha/test_voltha_alarm_events.py
index dd37a6e..7f7f015 100644
--- a/tests/itests/voltha/test_voltha_alarm_events.py
+++ b/tests/itests/voltha/test_voltha_alarm_events.py
@@ -1,16 +1,25 @@
 from unittest import main
 from common.utils.consulhelpers import get_endpoint_from_consul
-from tests.itests.test_utils import \
+from tests.itests.test_utils import get_pod_ip, \
     run_long_running_command_with_timeout
 from tests.itests.voltha.rest_base import RestBase
 from google.protobuf.json_format import MessageToDict
 from voltha.protos.device_pb2 import Device
 import simplejson, jsonschema
 import re
+from tests.itests.orch_environment import get_orch_environment
+from testconfig import config
 
 # ~~~~~~~ Common variables ~~~~~~~
 
 LOCAL_CONSUL = "localhost:8500"
+ENV_DOCKER_COMPOSE = 'docker-compose'
+ENV_K8S_SINGLE_NODE = 'k8s-single-node'
+
+orch_env = ENV_DOCKER_COMPOSE
+if 'test_parameters' in config and 'orch_env' in config['test_parameters']:
+    orch_env = config['test_parameters']['orch_env']
+print 'orchestration-environment: %s' % orch_env
 
 COMMANDS = dict(
     kafka_client_run="kafkacat -b {} -L",
@@ -43,15 +52,17 @@
 
 
 class VolthaAlarmEventTests(RestBase):
-    # Retrieve details on the REST entry point
-    rest_endpoint = get_endpoint_from_consul(LOCAL_CONSUL, 'envoy-8443')
+    # Get endpoint info
+    if orch_env == ENV_K8S_SINGLE_NODE:
+        rest_endpoint = get_pod_ip('voltha') + ':8443'
+        kafka_endpoint = get_pod_ip('kafka')
+    else:
+        rest_endpoint = get_endpoint_from_consul(LOCAL_CONSUL, 'voltha-envoy-8443')
+        kafka_endpoint = get_endpoint_from_consul(LOCAL_CONSUL, 'kafka')
 
     # Construct the base_url
     base_url = 'https://' + rest_endpoint
 
-    # Start by querying consul to get the endpoint details
-    kafka_endpoint = get_endpoint_from_consul(LOCAL_CONSUL, 'kafka')
-
     # ~~~~~~~~~~~~ Tests ~~~~~~~~~~~~
 
     def test_1_alarm_topic_exists(self):
@@ -105,6 +116,7 @@
     def add_device(self):
         device = Device(
             type='simulated_olt',
+            mac_address='00:00:00:00:00:01'
         )
         device = self.post('/api/v1/devices', MessageToDict(device),
                            expected_http_code=200)
diff --git a/tests/itests/voltha/test_voltha_xpon.py b/tests/itests/voltha/test_voltha_xpon.py
index a2375d9..6b0f66c 100644
--- a/tests/itests/voltha/test_voltha_xpon.py
+++ b/tests/itests/voltha/test_voltha_xpon.py
@@ -10,6 +10,8 @@
 from voltha.protos import bbf_fiber_traffic_descriptor_profile_body_pb2 as tdp
 from common.utils.consulhelpers import get_endpoint_from_consul
 from tests.itests.voltha.xpon_scenario import scenario as xpon_scenario
+from tests.itests.test_utils import get_pod_ip
+from testconfig import config
 
 '''
 These tests use the Ponsim OLT to verify create, update, and delete
@@ -31,8 +33,17 @@
 #for ordering the test cases
 id = 3
 LOCAL_CONSUL = "localhost:8500"
+
+orch_env = 'docker-compose'
+if 'test_parameters' in config and 'orch_env' in config['test_parameters']:
+    orch_env = config['test_parameters']['orch_env']
+print 'orchestration-environment: %s' % orch_env
+
 # Retrieve details of the REST entry point
-rest_endpoint = get_endpoint_from_consul(LOCAL_CONSUL, 'voltha-envoy-8443')
+if orch_env == 'k8s-single-node':
+    rest_endpoint = get_pod_ip('voltha') + ':8443'
+else:
+    rest_endpoint = get_endpoint_from_consul(LOCAL_CONSUL, 'voltha-envoy-8443')
 # Construct the base_url
 BASE_URL = 'https://' + rest_endpoint