예제 #1
0
 def test_get_from_failover(self):
     c = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
     data_id = "com.alibaba.cloud.acm:sample-app.properties"
     group = "group"
     key = "+".join([data_id, group, NAMESPACE])
     files.save_file(c.failover_base, key, "xxx")
     self.assertEqual(c.get(data_id, group), "xxx")
     shutil.rmtree(c.failover_base)
예제 #2
0
 def test_kms_encrypt(self):
     c = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
     c.set_options(kms_enabled=True,
                   kms_ak=KMS_AK,
                   kms_secret=KMS_SECRET,
                   region_id=REGION_ID,
                   key_id=KEY_ID)
     self.assertNotEqual(c.encrypt("中文"), "中文")
예제 #3
0
 def test_tls(self):
     c = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
     c.set_options(tls_enabled=True)
     data_id = "com.alibaba.cloud.acm:sample-app.properties-tlstest"
     group = "group"
     c.publish(data_id, group, "test")
     self.assertNotEqual(c.get(data_id, group), None)
     c.remove(data_id, group)
예제 #4
0
 def test_get_from_snapshot(self):
     c = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
     c.server_list = [("1.100.84.215", 8080, True)]
     data_id = "com.alibaba.cloud.acm:sample-app.properties"
     group = "group"
     key = "+".join([data_id, group, NAMESPACE])
     files.save_file(c.snapshot_base, key, "yyy")
     self.assertEqual(c.get(data_id, group), "yyy")
     shutil.rmtree(c.snapshot_base)
예제 #5
0
 def test_server_failover(self):
     acm.ACMClient.set_debugging()
     c = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
     c.server_list = [("1.100.84.215", 8080, True),
                      ("139.196.135.144", 8080, True)]
     c.current_server = ("1.100.84.215", 8080, True)
     data_id = "com.alibaba.cloud.acm:sample-app.properties"
     group = "group"
     self.assertNotEqual(c.get(data_id, group), None)
예제 #6
0
    def test_fake_watcher(self):
        data_id = "com.alibaba"
        group = "tsing"

        class Share:
            content = None
            count = 0

        cache_key = "+".join([data_id, group, ""])

        def test_cb(args):
            print(args)
            Share.count += 1
            Share.content = args["content"]

        c = acm.ACMClient(ENDPOINT)

        c.add_watcher(data_id, group, test_cb)
        c.add_watcher(data_id, group, test_cb)
        c.add_watcher(data_id, group, test_cb)
        time.sleep(1)
        c.notify_queue.put((cache_key, "xxx", "md51"))
        time.sleep(2)
        self.assertEqual(Share.content, "xxx")
        self.assertEqual(Share.count, 3)

        c.remove_watcher(data_id, group, test_cb)
        Share.count = 0
        c.notify_queue.put((cache_key, "yyy", "md52"))
        time.sleep(2)
        self.assertEqual(Share.content, "yyy")
        self.assertEqual(Share.count, 2)

        c.remove_watcher(data_id, group, test_cb, True)
        Share.count = 0
        c.notify_queue.put((cache_key, "not effective, no watchers", "md53"))
        time.sleep(2)
        self.assertEqual(Share.content, "yyy")
        self.assertEqual(Share.count, 0)

        Share.count = 0
        c.add_watcher(data_id, group, test_cb)
        time.sleep(1)
        c.notify_queue.put((cache_key, "zzz", "md54"))
        time.sleep(2)
        self.assertEqual(Share.content, "zzz")
        self.assertEqual(Share.count, 1)

        Share.count = 0
        c.notify_queue.put(
            (cache_key, "not effective, md5 no changes", "md54"))
        time.sleep(2)
        self.assertEqual(Share.content, "zzz")
        self.assertEqual(Share.count, 0)
예제 #7
0
 def test_publish_remove(self):
     c = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
     data_id = "com.alibaba.cloud.acm:sample-app.properties"
     group = "acm"
     content = u"test中文"
     c.remove(data_id, group)
     time.sleep(0.5)
     self.assertIsNone(c.get(data_id, group))
     c.publish(data_id, group, content)
     time.sleep(0.5)
     self.assertEqual(c.get(data_id, group), content)
예제 #8
0
    def __init__(self, endpoint, namespace, access_key, secret_key):
        # Variables
        self.endpoint = endpoint
        self.namespace = namespace
        self.access_key = access_key
        self.secret_key = secret_key

        # Initialize ACM instance
        self._client = acm.ACMClient(endpoint=self.endpoint,
                                     namespace=self.namespace,
                                     ak=self.access_key,
                                     sk=self.secret_key)
        pass
예제 #9
0
    def test_server_failover_comp(self):
        acm.ACMClient.set_debugging()
        c = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
        c.get_server()
        c.server_list = [("1.100.84.215", 8080, True), ("100.196.135.144", 8080, True)]
        c.current_server = ("1.100.84.215", 8080, True)
        data_id = "com.alibaba.cloud.acm:sample-app.properties"
        group = "group"
        shutil.rmtree(c.snapshot_base, True)
        self.assertEqual(c.get(data_id, group), None)

        time.sleep(31)
        shutil.rmtree(c.snapshot_base, True)
        self.assertNotEqual(c.get(data_id, group), None)
예제 #10
0
    def load_config_from_acm():
        if ACMConfigManager.acm_sdk_config is not None:
            _acm = acm.ACMClient(ACMConfigManager.acm_sdk_config['endpoint'],
                                 ACMConfigManager.acm_sdk_config['namespace'],
                                 ACMConfigManager.acm_sdk_config['ak'],
                                 ACMConfigManager.acm_sdk_config['sk'])
        else:
            print('error')
            log.warning('ACM configuration not found in config file')
            return None

        config_str = _acm.get(ACMConfigManager.acm_sdk_config['data_id'],
                              ACMConfigManager.acm_sdk_config['group'])
        print(config_str)
예제 #11
0
    def test_long_pulling(self):
        acm.ACMClient.set_debugging()
        c = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)

        class Share:
            content = None

        def cb(x):
            Share.content = x["content"]
            print(Share.content)

        # test common
        data_id = "com.alibaba.cloud.acm:sample-app.properties"
        group = "group"
        c.add_watcher(data_id, group, cb)
        time.sleep(10)
        self.assertNotEqual(Share.content, None)
예제 #12
0
    def test_get_server_err(self):
        c2 = acm.ACMClient("100.100.84.215:8080")
        self.assertEqual(c2.get_server(), None)

        c3 = acm.ACMClient("10.101.84.215:8081")
        self.assertEqual(c3.get_server(), None)
예제 #13
0
 def test_key_decrypt(self):
     c = acm.ACMClient(ENDPOINT, NAMESPACE, KMS_AK, KMS_SECRET)
     c.set_options(kms_enabled=True, region_id=REGION_ID)
     value = "test"
     self.assertEqual(c.get("cipher-test_python", None), value)
예제 #14
0
 def test_get_server(self):
     acm.ACMClient.set_debugging()
     c = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
     self.assertEqual(type(c.get_server()), tuple)
예제 #15
0
 def test_list_all(self):
     c = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
     c.set_debugging()
     self.assertGreater(len(c.list_all()), 1)
예제 #16
0
import acm
import time

ENDPOINT = "addr-sz-internal.edas.aliyun.com:8080"
NAMESPACE = "vanke-yiyun-prod"
AK = "LTAIry88qsasWzSD"
SK = "4A4Zzz2DtdgaU6xplhtq7NkgRUMFAs"

# get config
client = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
client.set_options(region_id="cn-shenzhen")
client.list_all()
예제 #17
0
 def test_unit(self):
     acm.ACMClient.set_debugging()
     c = acm.ACMClient(ENDPOINT, unit_name=UNIT_NAME)
     self.assertEqual(type(c.get_server()), tuple)
예제 #18
0
 def test_no_auth(self):
     c = acm.ACMClient("jmenv.tbsite.net:8080")
     data_id = "com.alibaba"
     group = ""
     self.assertEqual(c.get(data_id, group), None)
예제 #19
0
 def test_get_server_no_cai(self):
     c = acm.ACMClient("11.162.248.130:8080")
     c.set_options(cai_enabled=False)
     data_id = "com.alibaba"
     group = ""
     self.assertEqual(c.get(data_id, group), None)
예제 #20
0
 def test_get_key(self):
     c = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
     data_id = "com.alibaba.cloud.acm:sample-app.properties"
     group = "group"
     print(c.get(data_id, group))
     self.assertNotEqual(c.get(data_id, group), None)
예제 #21
0
def getDbConfig():
    global dbConfig
    if dbConfig == None:
        acmClient = acm.ACMClient(ACM_ENDPOINT, ACM_NAMESPACE, AK, SK)
        dbConfig = json.loads(acmClient.get(ACM_DATA_ID, ACM_GROUP))
    return dbConfig
예제 #22
0
파일: signals.py 프로젝트: iamsk/clovers
from django.conf import settings
from django.db.models.signals import post_save
import json
import acm

from .models import Configuration


def sync(sender, instance, **kwargs):
    content = json.dumps(instance.data)
    c.publish(data_id=instance.name, group=settings.ALIYUN_ACM['GROUP'], content=content)


if settings.ALIYUN_ACM:
    c = acm.ACMClient(settings.ALIYUN_ACM['ENDPOINT'], settings.ALIYUN_ACM['NAMESPACE'], settings.ALIYUN_ACM['AK'],
                      settings.ALIYUN_ACM['SK'])
    post_save.connect(sync, sender=Configuration)
예제 #23
0
 def test_publish(self):
     c = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
     data_id = "com.alibaba.cloud.acm:sample-app.properties"
     group = "group"
     content = "test"
     c._publish(data_id, group, content)