Skip to content

Commit

Permalink
Random fixes to make interfaces more consistent
Browse files Browse the repository at this point in the history
Move file handling for import/export of service group
and service data into the shell commands leaving the
group and data code independent of the ultimate file
format (shell commands use TOML with configuration
expansions).

Update shell test to include the common "service_host"
binding variable that we use throughout other tests.

Signed-off-by: Mic Bowman <mic.bowman@intel.com>
  • Loading branch information
cmickeyb authored and prakashngit committed Sep 14, 2023
1 parent c25b001 commit feef8ed
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 54 deletions.
83 changes: 43 additions & 40 deletions build/tests/shell-test.psh
Original file line number Diff line number Diff line change
Expand Up @@ -16,76 +16,79 @@

set --conditional -s data -v .
set --conditional -s save -v .
set --conditional -s service_host -v ${host}

if --null "${tmpfile}"
echo must specify tmpfile for test
exit -v -1
fi

## echo running tests on ${service_host}

## create an eservice db with the known enclave services
service_db clear
service_db add --url http://${host}:7101 --name es7101 --type eservice
service_db add --url http://${host}:7102 --name es7102 --type eservice
service_db add --url http://${host}:7103 --name es7103 --type eservice
service_db add --url http://${host}:7104 --name es7104 --type eservice
service_db add --url http://${host}:7105 --name es7105 --type eservice
service_db add --url http://${service_host}:7101 --name es7101 --type eservice
service_db add --url http://${service_host}:7102 --name es7102 --type eservice
service_db add --url http://${service_host}:7103 --name es7103 --type eservice
service_db add --url http://${service_host}:7104 --name es7104 --type eservice
service_db add --url http://${service_host}:7105 --name es7105 --type eservice

## default pservice group
pservice add --url http://${host}:7001
pservice add --url http://${host}:7002
pservice add --url http://${host}:7003
pservice add --url http://${service_host}:7001
pservice add --url http://${service_host}:7002
pservice add --url http://${service_host}:7003

## pservice group p1
pservice add --group p1 --url http://${host}:7003
pservice add --group p1 --url http://${host}:7004
pservice add --group p1 --url http://${host}:7005
pservice add --group p1 --url http://${service_host}:7003
pservice add --group p1 --url http://${service_host}:7004
pservice add --group p1 --url http://${service_host}:7005

## pservice group all
pservice add --group all --url http://${host}:7001
pservice add --group all --url http://${host}:7002
pservice add --group all --url http://${host}:7003
pservice add --group all --url http://${host}:7004
pservice add --group all --url http://${host}:7005
pservice add --group all --url http://${service_host}:7001
pservice add --group all --url http://${service_host}:7002
pservice add --group all --url http://${service_host}:7003
pservice add --group all --url http://${service_host}:7004
pservice add --group all --url http://${service_host}:7005

## default eservice group
eservice add --url http://${host}:7101
eservice add --url http://${host}:7102
eservice add --url http://${host}:7103
eservice add --url http://${service_host}:7101
eservice add --url http://${service_host}:7102
eservice add --url http://${service_host}:7103

## eservice group e1
eservice add --group e1 --name es7103 es7104 es7105
eservice use --group e1 --url http://${host}:7105
eservice use --group e1 --url http://${service_host}:7105

## eservice group all
eservice add --group all --url http://${host}:7101
eservice add --group all --url http://${host}:7102 http://${host}:7103 --name es7104 es7105
eservice add --group all --url http://${service_host}:7101
eservice add --group all --url http://${service_host}:7102 http://${service_host}:7103 --name es7104 es7105
eservice use --group all --name es7104

## default sservice group
set -s persistent_storage_service -v http://${host}:7201
set -s persistent_storage_service -v http://${service_host}:7201

sservice add --url http://${host}:7201
sservice add --url http://${host}:7202
sservice add --url http://${host}:7203
sservice add --url http://${service_host}:7201
sservice add --url http://${service_host}:7202
sservice add --url http://${service_host}:7203
sservice set --duration 120 --replicas 2 --persistent ${persistent_storage_service}

## sservice group s1
sservice add --group s1 --url http://${host}:7203
sservice add --group s1 --url http://${host}:7204
sservice add --group s1 --url http://${host}:7205
sservice add --group s1 --url http://${service_host}:7203
sservice add --group s1 --url http://${service_host}:7204
sservice add --group s1 --url http://${service_host}:7205
sservice set --group s1 --duration 120 --replicas 2 --persistent ${persistent_storage_service}

## sservice group s2
sservice add --group s2 --url http://${host}:7201
sservice add --group s2 --url http://${host}:7202
sservice add --group s2 --url http://${service_host}:7201
sservice add --group s2 --url http://${service_host}:7202
sservice set --group s2 --duration 120 --replicas 1 --persistent ${persistent_storage_service}

## all sservices
sservice add --group all --url http://${host}:7201
sservice add --group all --url http://${host}:7202
sservice add --group all --url http://${host}:7203
sservice add --group all --url http://${host}:7204
sservice add --group all --url http://${host}:7205
sservice add --group all --url http://${service_host}:7201
sservice add --group all --url http://${service_host}:7202
sservice add --group all --url http://${service_host}:7203
sservice add --group all --url http://${service_host}:7204
sservice add --group all --url http://${service_host}:7205
sservice set --group all --duration 3600 --replicas 3 --persistent ${persistent_storage_service}

## create some contracts
Expand All @@ -108,8 +111,8 @@ fi

identity -n user2
contract create -c mock-contract --source _mock-contract -r all -p all -e all -f ${save}/${contract2}.pdo
contract send -f ${save}/${contract2}.pdo --wait inc_value -e http://${host}:7101
contract send -f ${save}/${contract2}.pdo --wait inc_value -e http://${host}:7102
contract send -f ${save}/${contract2}.pdo --wait inc_value -e http://${service_host}:7101
contract send -f ${save}/${contract2}.pdo --wait inc_value -e http://${service_host}:7102
contract send -f ${save}/${contract2}.pdo --wait inc_value -e random
contract send -f ${save}/${contract2}.pdo --wait inc_value -e random
contract send -f ${save}/${contract2}.pdo get_value -s value
Expand Down Expand Up @@ -157,7 +160,7 @@ fi
service_groups save --file ${tmpfile}

## create a new group that should be overwritten by a no-merge load
sservice add --group group_test --url http://${host}:7201
sservice add --group group_test --url http://${service_host}:7201
sservice set --group group_test --duration 3600 --replicas 3 --persistent ${persistent_storage_service}

service_groups load --file ${tmpfile} --no-merge
Expand All @@ -177,7 +180,7 @@ if --null "${_group_test_sym_}"
fi

## create a new group that should be available after a merge load
sservice add --group group_test --url http://${host}:7201
sservice add --group group_test --url http://${service_host}:7201
sservice set --group group_test --duration 3600 --replicas 3 --persistent ${persistent_storage_service}

service_groups load --file ${tmpfile} --merge
Expand Down
12 changes: 9 additions & 3 deletions client/pdo/client/commands/service_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
# limitations under the License.

import json
import toml

import pdo.client.builder.shell as pshell
import pdo.client.builder.script as pscript
import pdo.common.config as pconfig
import pdo.common.utility as putils
from pdo.service_client.service_data.service_data import ServiceDatabaseManager as service_data

Expand Down Expand Up @@ -276,8 +278,9 @@ def add_arguments(cls, subparser) :

@classmethod
def invoke(cls, state, bindings, filename, **kwargs) :
data_file = putils.find_file_in_path(filename, state.get(['Client', 'SearchPath'], ['.', './etc/']))
service_data.local_service_manager.import_service_information(data_file)
filename = putils.find_file_in_path(filename, state.get(['Client', 'SearchPath'], ['.', './etc/']))
services = pconfig.parse_configuration_file(filename, bindings)
service_data.local_service_manager.import_service_information(services)
return True

## -----------------------------------------------------------------
Expand All @@ -295,7 +298,10 @@ def add_arguments(cls, subparser) :

@classmethod
def invoke(cls, state, bindings, filename, **kwargs) :
service_data.local_service_manager.export_service_information(filename)
services = service_data.local_service_manager.export_service_information()
with open(filename, "w") as sf :
toml.dump(services, sf)

return True

## -----------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions client/pdo/client/commands/service_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import pdo.client.builder.shell as pshell
import pdo.client.builder.script as pscript
import pdo.common.utility as putils
import pdo.common.config as pconfig

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -64,8 +65,7 @@ def add_arguments(cls, subparser) :
def invoke(cls, state, bindings, filename, merge=True, **kwargs) :
try :
filename = putils.find_file_in_path(filename, state.get(['Client', 'SearchPath'], ['.', './etc']))
with open(filename, "r") as infile:
info = toml.load(infile)
info = pconfig.parse_configuration_file(filename, bindings)

psgroups = info.get('ProvisioningServiceGroups', {})
ssgroups = info.get('StorageServiceGroups', {})
Expand Down
17 changes: 8 additions & 9 deletions python/pdo/service_client/service_data/service_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
import json
import lmdb
import os
import random
import string
import toml

import pdo.common.config as pconfig
import pdo.common.logger as plogger
Expand Down Expand Up @@ -529,9 +526,9 @@ def store_by_url(self, url, service_type='eservice', service_names=[], service_i
return service_info

# -----------------------------------------------------------------
def import_service_information(self, filename) :
with open(filename, "r") as sf :
services = toml.load(sf)
def import_service_information(self, services) :
"""Bulk add of services to the database
"""

service_file_keys = [
('eservice', 'EnclaveService'),
Expand Down Expand Up @@ -566,7 +563,10 @@ def import_service_information(self, filename) :
service_identity=service_identity)

# -----------------------------------------------------------------
def export_service_information(self, filename) :
def export_service_information(self) :
"""Bulk dump of all services from the database
"""

service_file_keys = [
('eservice', 'EnclaveService'),
('pservice', 'ProvisioningService'),
Expand All @@ -584,5 +584,4 @@ def export_service_information(self, filename) :

services[service_class].append(export_service_info)

with open(filename, "w") as sf :
toml.dump(services, sf)
return services

0 comments on commit feef8ed

Please sign in to comment.