發表文章

產生SSL憑證讓nginx使用

$ sudo mkdir /etc/nginx/ssl $ cd /etc/nginx/ssl $ sudo openssl genrsa -des3 -out server.key 2048 $ sudo openssl req -new -key server.key -out server.csr $ sudo cp server.key server.key.org $ sudo openssl rsa -in server.key.org -out server.key $ sudo openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt $ vi /etc/nginx/conf.d/ssl.conf # HTTPS server server { listen 443; server_name example.com; ssl on; ssl_certificate /etc/nginx/ssl/server.crt; ssl_certificate_key /etc/nginx/ssl/server.key; } $ /etc/init.d/nginx restart 參考連結: https://www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on-nginx-for-centos-6

Python - 執行且客製HTMLTestRunner的report

圖片
$ wget -P /usr/lib/python2.7 http://tungwaiyip.info/software/HTMLTestRunner_0_8_2/HTMLTestRunner.py # 編輯執行unittest 的py檔 # 先宣告產生的html檔案存放路徑 tests = ['test_case_1', 'test_case_2' ] suite = unittest.TestSuite(map(BackUpTest,tests)) testfile = "/tmp/test.html" fp = file(testfile,"wb") runner = HTMLTestRunner.HTMLTestRunner(stream=fp) runner.run(suite) 我們用HTMLTestRunner(0.8.2)來產生unittest report 預設輸出的畫面如下   今天我們想在每個test case加上 自己的docstring該如何做呢? 最終畫面如下 # HTMLTestRunner.py # 第416行開始就是產生report的html語法 # 第一步 在header_row先加入一個"Description"的欄位 # 接著在"Total"那一列需加入一個空白欄位 # 如果是想顯示Class Unittest Module的docstring,需再產生class report template的腳本先新增一個%(docstring)s的變數欄位 # 這邊的 %( docstring )s 可以自行定義 # 如果是想顯示每個unitest function的docstring需在產生unittest report template的腳本新增一個 %(docstring)s的變數欄位 # 因為產生unittest report的有分有output及沒有output,所以兩個地方要改 # 一樣這邊 的 %( docstring )s 可以自行定義 # 我們這邊就要在_generate_...

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 $...