發表文章

目前顯示的是 6月, 2016的文章

Python - unittest

參考來源 : 使用PYTHON的UNITTEST做测试 python 的 unittest 单元测试使用详解 Python unittest 模組 Part 1 利用 Coverage 計算 Python 程式碼的涵蓋率 Python 單元測試(Unit Testing) [Python]如何使用HtmlTestRunner让自动化测试报告内容更丰富 04、生成 HTMLTestRunner 测试报告 unittest colored output

CEPH - health HEALTH_WARN crush map has legacy tunables (require bobtail, min is firefly)

當用以下cmd查詢ceph的健康狀態時。 $ ceph -s cluster 6462f5bb-f440-445c-a5ff-e77a7ca38ed6 health HEALTH_WARN crush map has legacy tunables (require bobtail, min is firefly) monmap e1: 1 mons at {ceph-mon=192.168.100.2:6789/0} election epoch 1, quorum 0 ceph-mon osdmap e79: 3 osds: 3 up, 3 in pgmap v172285: 1080 pgs, 15 pools, 43160 kB data, 350 objects 280 MB used, 8901 MB / 9182 MB avail 1080 active+clean # 可以嘗試下列指令,恩為可能無法map device,更動過crush演算法。 $ ceph osd crush tunables firefly $ ceph osd crush tunables default $ ceph osd crush tunables optimal

Python - bytes reversed ABCDEF -> EFCDAB

#!/usr/bin/python #-*- coding:utf-8 -*- ''' @author: Duncan ''' # option1 Byte = 'ABCDEF' print "".join(reversed([Byte[i:i+2] for i in range(0, len(Byte), 2)])) # option2 temp_list = [] for i in range(0, len(Byte), 2): temp_list.append(Byte[i:i+2]) print "".join(reversed(temp_list)) 參考來源 :  Reverse a string in Python two characters at a time (Network byte order)

Python - 計算特定目錄底下的檔案以及目錄數量

$ vim countFileandFolder.py import os import sys fileList = [] fileSize = 0 folderCount = 0 rootdir = '/usr/lib' for root, subFolders, files in os.walk(rootdir): folderCount += len(subFolders) for file in files: f = os.path.join(root,file) fileSize = fileSize + os.path.getsize(f) #print(f) fileList.append(f) print("Total Size is {0} bytes".format(fileSize)) print(“Total Files “, len(fileList)) print(“Total Folders “, folderCount) 參考來源 :   recursive list files in a dir using Python

Python - multithread

#!/usr/bin/python #-*- coding:utf-8 -*- ''' @author: Duncan ''' from Queue import Queue from threading import Thread class ThreadWorker(Thread): def __init__(self, name, tasks): Thread.__init__(self) self.tasks = tasks # tasks queue self.daemon = True # 需在start之前,具有和main thread一同終止的特性,預設是False self.start() self.name = name # 可以分別設定thread的name   def run(self): while True: func, args, kargs = self.tasks.get() # 從tasks queue取出task   try: func(*args, **kargs) # 執行function except Exception as e: print e self.tasks.task_done() class ThreadPoolManager: def __init__(self, number_threads):   self.tasks = Queue( ) # 建立沒有限制長度的queue for _ in range( number_threads ): ThreadWorker(_,self.tasks) # 啟動根據 num_threads數量的task任務 def add_task(self, func, *args, **ka

利用opensource 安裝openstack 結合 linuxbridge與vxlan– Multinode (kilo)

==環境說明==  OS: ubuntu 14.04 x86_64 HostName Eth0(Management) Eth1(Public) controller 172.20.3.49 compute1 172.20.3.58 network 172.20.3.62 192.168.100.17 storage 172.20.3.54 ==前置作業== 編輯四台的/etc/hosts,方便利用主機名稱進行訪問 $ cat >> /etc/hosts << EOF 172.20.3.49 controller 172.20.3.58 compute1 172.20.3.62 network 172.20.3.54 storage EOF 三台都更新套件 $ apt-get update; apt-get dist-upgrade -y;reboot 在這三台都建立openstack 相關服務的使用者,我們利用下面的腳本幫我們創立 # 新增一個 createOpenstackServiceUsers.sh腳本 $ vim createOpenstackServiceUsers.sh # 把下面內容複製貼上 #!/bin/bash for SERVICE in keystone glance neutron nova horizon cinder do useradd --home-dir "/var/lib/$SERVICE" --create-home --system --shell /bin/false $SERVICE #Create essential dirs mkdir -p /var/log/$SERVICE mkdir -p /etc/$SERVICE #Set ownership of the dirs chown -R $SERVICE:$SERVICE /var/log/$SERVICE chown -R $SERVICE:$SERVICE /var/lib/$SERVICE chown $