Merge remote-tracking branch 'origin/master' into merge-branch
[netvirt.git] / paxexam / plugin.integrationtest / src / test / java / org / opendaylight / ovsdb / plugin / OvsdbTestBase.java
1 /*
2  * Copyright (c) 2014 Red Hat, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Authors : Madhu Venugopal
9  */
10 package org.opendaylight.ovsdb.plugin;
11
12 import java.io.IOException;
13 import java.util.HashMap;
14 import java.util.Map;
15 import java.util.Properties;
16
17 import org.opendaylight.controller.sal.connection.ConnectionConstants;
18 import org.opendaylight.controller.sal.core.Node;
19 import org.opendaylight.controller.sal.utils.ServiceHelper;
20
21 public abstract class OvsdbTestBase {
22     private final static String identifier = "TEST";
23
24     public Node getTestConnection() throws IOException {
25         IConnectionServiceInternal connectionService = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class,
26                 this);
27         Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
28         Properties props = System.getProperties();
29         params.put(ConnectionConstants.ADDRESS,
30                 props.getProperty("ovsdbserver.ipaddress"));
31         params.put(ConnectionConstants.PORT,
32                 props.getProperty("ovsdbserver.port", "6640"));
33
34         Node node = connectionService.connect(identifier, params);
35         if (node == null) {
36             throw new IOException("Failed to connect to the ovsdb server");
37         }
38         return node;
39     }
40 }