From 761f2ec02c59571bd5950c4cf9b9b5faf3f192fe Mon Sep 17 00:00:00 2001 From: YangYong3 Date: Tue, 7 Mar 2017 12:56:13 +0900 Subject: [PATCH] joyent/node-triton#116 `triton package list name=~foo` doesn't seem to filter package ~ --- lib/papi.js | 7 ++++++- test/api.test.js | 8 ++++++++ tools/rsync-to | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100755 tools/rsync-to diff --git a/lib/papi.js b/lib/papi.js index 54aac21..75460a6 100644 --- a/lib/papi.js +++ b/lib/papi.js @@ -815,7 +815,12 @@ function searchFilter(params, schema) { } } else { if (name !== 'owner_uuids') { - constraint = '(' + name + '=' + esc(value) + ')'; + if (value.toString().charAt(0) === '~') { + value = value.toString().substr(1, value.toString().length); + constraint = '(' + name + '=' + esc(value) + '*)'; + } else { + constraint = '(' + name + '=' + esc(value) + ')'; + } } else { constraint = '(|(' + name + '=' + esc(value) + ')(!(owner_uuids=*)))'; diff --git a/test/api.test.js b/test/api.test.js index fd58752..9e0c868 100644 --- a/test/api.test.js +++ b/test/api.test.js @@ -570,7 +570,15 @@ test('GET /packages (Search by name)', function (t) { searchAndCheckPkgs(t, query, testFilter); }); +test('GET /packages (Search by substring name)', function (t) { + var query = '/packages?name=~api_test'; + var testFilter = function (p) { + return /^api_test_/.test(p.name); + }; + + searchAndCheckPkgs(t, query, testFilter); +}); test('GET /packages (Search by wildcard)', function (t) { var query = '/packages?name=api_test_*'; diff --git a/tools/rsync-to b/tools/rsync-to new file mode 100755 index 0000000..d2bdcf9 --- /dev/null +++ b/tools/rsync-to @@ -0,0 +1,51 @@ +#!/bin/bash +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# +# Copyright (c) 2015, Joyent, Inc. +# + +# +# Rsync the master in this working copy to the install on the given HN. +# + +#set -o xtrace +set -o errexit + +TOP=$(cd $(dirname $0)/../; pwd) +NODE="root@$1" + +if [[ -z "$PAPI_ZONE" ]]; then + PAPI_ZONE=$(ssh $NODE "vmadm lookup -1 alias=papi0" 2>/dev/null) +fi +echo "PAPI_ZONE: $PAPI_ZONE" + +extraOpts= +if [[ $(uname -s) != "SunOS" ]]; then + extraOpts="--exclude *.node --exclude build" +else + # Clean node_modules everytime. + ssh $NODE rm -rf /zones/$PAPI_ZONE/root/opt/smartdc/papi/node_modules +fi + +rsync -av ${TOP}/ \ + $NODE:/zones/$PAPI_ZONE/root/opt/smartdc/papi/ \ + $extraOpts \ + --exclude .git/ \ + --exclude /config.json \ + --exclude /deps/ \ + --exclude /doc/ \ + --exclude /tools/ \ + --exclude /tmp/ \ + +state=$(ssh ${NODE} svcs -z ${PAPI_ZONE} -H -o state papi) +if [[ "$state" == "maintenance" ]]; then + ssh ${NODE} svcadm -z ${PAPI_ZONE} clear papi +else + ssh ${NODE} svcadm -z ${PAPI_ZONE} restart papi +fi +