From bebd5545c6f215c6daf29ab6b562ee077d41a800 Mon Sep 17 00:00:00 2001 From: Yan Gorelik Date: Wed, 30 Jan 2019 11:55:54 -0800 Subject: [PATCH] Enhancement #853 --- .gitignore | 1 - .travis.yml | 2 +- sdk/cpp/core/src/path/repository.cpp | 7 +++++- sdk/cpp/gnmi/tests/test_gnmi_provider.cpp | 27 ++++++++++++++++++++++- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 96519bc6b..88aea2e2e 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,3 @@ protobuf-3.5.0 sdk/python/gnmi/build sdk/python/gnmi/dist sdk/python/gnmi/ydk_service_gnmi.egg-info -sdk/cpp/core/tests/repository/* diff --git a/.travis.yml b/.travis.yml index 3173c0a5f..eac230e5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ matrix: dist: trusty group: edge - os: osx - osx_image: xcode8.3 + osx_image: xcode7.3 language: generic # - os: osx # env: GNMI=true diff --git a/sdk/cpp/core/src/path/repository.cpp b/sdk/cpp/core/src/path/repository.cpp index 54b787e99..58a2396f9 100644 --- a/sdk/cpp/core/src/path/repository.cpp +++ b/sdk/cpp/core/src/path/repository.cpp @@ -235,7 +235,12 @@ ly_ctx* ydk::path::RepositoryPtr::create_ly_context() { for(auto model_provider : get_model_providers()) { - path+="/"+model_provider->get_hostname_port(); + //path+="/"+model_provider->get_hostname_port(); + auto hostname_port = model_provider->get_hostname_port(); + auto underscore_pos = hostname_port.rfind("_"); + if (underscore_pos != std::string::npos) + hostname_port = hostname_port.substr(0, underscore_pos); + path += "/" + hostname_port; break; } } diff --git a/sdk/cpp/gnmi/tests/test_gnmi_provider.cpp b/sdk/cpp/gnmi/tests/test_gnmi_provider.cpp index aa29d6332..4a47227bb 100644 --- a/sdk/cpp/gnmi/tests/test_gnmi_provider.cpp +++ b/sdk/cpp/gnmi/tests/test_gnmi_provider.cpp @@ -15,6 +15,10 @@ ------------------------------------------------------------------*/ #include #include +#include +#include +#include +#include #include #include @@ -45,9 +49,30 @@ TEST_CASE("GNMICreateNoRepo") CHECK_NOTHROW(provider.get_encoding()); } +static std::string get_temp_model_path() +{ + const char *homeDir = getenv("HOME"); + if (!homeDir) { + struct passwd* pwd = getpwuid(getuid()); + if (pwd) + homeDir = pwd->pw_dir; + } + + std::ostringstream models_path{}; + models_path << homeDir << "/.ydk/temp"; + auto path = models_path.str(); + + struct stat st; + memset(&st, 0, sizeof(struct stat)); + if (stat(path.c_str(), &st) == -1) { + mkdir(path.c_str(), 0755); + } + return path; +} + TEST_CASE("GNMICreateWithNoFiles") { - ydk::path::Repository repo{}; + ydk::path::Repository repo{get_temp_model_path()}; gNMIServiceProvider provider{repo, "127.0.0.1", 50051, "admin", "admin"}; gNMIService gs{};