2016年4月19日 星期二

笔记:Ubuntu下快速开始使用Python Thrift

http://sunliwen.com/2012/02/apache-thrift-on-ubuntu-10-04/


笔记:Ubuntu下快速开始使用Python Thrift

本文介绍如何在Ubuntu 10.04下安装Apache Thrift并用Python写一个Demo。
apt-get install libboost-dev libevent-dev python-dev automake pkg-config libtool flex bison sun-java6-jdk
wget http://www.apache.org/dist//thrift/0.8.0/thrift-0.8.0.tar.gz
tar zxvf thrift-0.8.0.tar.gz
cd thrift-0.8.0
./configure
make
sudo make install
sudo pip install thrift
编辑接口文件 hellowworld.thrift:
service HelloWorld {
    string ping(),
    string say(1:string msg)
}
编辑 server.py
#!/usr/bin/env python
 
import socket
import sys
sys.path.append('./gen-py')
 
from helloworld import HelloWorld
from helloworld.ttypes import *
 
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
 
class HelloWorldHandler:
  def ping(self):
    return "pong"
 
  def say(self, msg):
    ret = "Received: " + msg
    print ret
    return ret
 
handler = HelloWorldHandler()
processor = HelloWorld.Processor(handler)
transport = TSocket.TServerSocket("localhost", 9090)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
 
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
 
print "Starting thrift server in python..."
server.serve()
print "done!"
编辑 client.py
#!/usr/bin/env python
 
import sys
sys.path.append('./gen-py')
 
from helloworld import HelloWorld
 
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
 
try:
  transport = TSocket.TSocket('localhost', 9090)
  transport = TTransport.TBufferedTransport(transport)
  protocol = TBinaryProtocol.TBinaryProtocol(transport)
  client = HelloWorld.Client(protocol)
  transport.open()
 
  print "client - ping"
  print "server - " + client.ping()
 
  print "client - say"
  msg = client.say("Hello!")
  print "server - " + msg
 
  transport.close()
 
except Thrift.TException, ex:
  print "%s" % (ex.message)
thrift --gen py helloworld.thrift
python server.py
python client.py

2016年4月14日 星期四

Installing C++ 4.8.5 on CentOS 6.7

With yum on CentOS, the most updated gcc version are
gcc 4.1.2 for CentOS 5
gcc 4.4.7 for CentOS 6
gcc 4.8.5 for CentOS 7

What if you want to have higher version to run on CentOS 6? This article is going to tell you how to compile gcc on CentOS 6.7 which is the final version of CentOS.

First you are going to download CentOS 6.7 DVD1 ISO file.
http://centos.uhost.hk/6.7/isos/x86_64/CentOS-6.7-x86_64-bin-DVD1.iso

I used VMWare Workstation 12 Player to host the virtual machine. As it supports "Linux Easy Install", simply mount the ISO to a newly created VM, start it to enter user name and password. After 15 minutes, it will bring you to the Linux installed environment.


Install gcc compiler
First thing to to is to use terminal to install the most updated compiler. It will be used to compile the new compiler. Yes. gcc is compiled using its gcc compiler.
sudo yum install gcc-c++

Install glibc
sudo yum install -y gcc texinfo-tex flex zip libgcc.i686 glibc-devel.i686

Download gcc source code
wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.gz

Download mpc, mpfr, gmp package
tar zxf gcc-4.8.5.tar.gz
cd gcc-4.8.5
./contrib/download_prerequisites

Compile gcc
mkdir gcc-build-4.8.5
cd gcc-build-4.8.5
../configure --prefix=/usr
sudo make && make install

Check your gcc versions
gcc --version
gcc (GCC) 4.8.5
g++ --version
g++ (GCC) 4.8.5
which gcc
/usr/bin/gcc
which g++
/usr/bin/g++

After 2 hours of compilation, you will be able to see the below installed log.


Test the compilation:

cat >test.cc <<EOF
#include <iostream>
using namespace std;
int main() {
  cout << "Hello, World!" << endl;
  return 0;
}
EOF

g++ -o test.exe -g -Wall test.cc

./test.exe

Hello, World!

Check rpm installed
Because you are compiling gcc on your own, yum or rpm are unware of the new gcc version.
rpm -qa | grep gcc
gcc-4.4.7-16.el6.x86_64
libgcc-4.4.7-16.el6.x86_64
libgcc-4.4.7-16.el6.i686
gcc-c++-4.4.7-16.el6.x86_64

2016年4月7日 星期四

Linux CentOS 6.7 and 7 C++ Java Netbeans Python RobotFramework SQLite

Linux CentOS 7 C++ Java Netbeans Eclipse CDT Python RobotFramework
Basic

Download CentOS 7 Everything
Install minimal, 512MB RAM minimal for CentOS 6.9

Add sudoer
adduser ricky
passwd ricky
usermod -aG wheel ricky
echo 'ricky ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers (CentOS 6, maybe 7 also ok)
su - ricky
sudo ls -lart /root

NIC onboot
sudo ifup eth0
vi /etc/sysconfig/network-scritps/ifcfg-eth0
onboot=yes

Install ifconfig, netstats, traceroute
sudo yum -y install net-tools


Set Host Name (CentOS 7 only, optional for X11)
sudo hostnamectl set-hostname centos72

Set Host Name (CentOS 6 only, optional for X11)
sudo vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=centos6

Change SSHD config
sudo vi /etc/ssh/sshd_config
  • X11Forwarding yes
  • X11UseLocalhost no
Install xauth and xclock
sudo yum -y install xauth xclock openssh-clients

Common

Change Time Zone to HKT
sudo ln -sf /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
date

Enable line number in VI
sudo yum install -y vim
printf "set number" > ~/.vimrc

Install wget

sudo yum install -y wget

NTP Service (CentOS 7)
sudo yum -y install ntp
sudo service ntpd start
ntpq -p

NTP Restart (CentOS 7)
sudo vi /etc/ntp.conf
server 192.168.0.1 iburst
sudo service ntpd restart
ntpq -p

NTP (CentOS 6)
sudo yum -y install ntp ntpdate ntp-doc
sudo chkconfig ntpd on
sudo ntpdate pool.ntp.org
sudo /etc/init.d/ntpd start

ACPI Shutdown
sudo yum -y install acpid
sudo chkconfig acpid on (CentOS 6)
sudo service acpid start (CentOS 6)
systemctl enable acpid.service
systemctl start acpid.service

Check $DISPLAY

Check Host File for $DISPLAY
sudo vi /etc/hosts
192.168.0.101 centos7

Check $DISPLAY after reboot
For CentOS 6,
sudo service sshd restart
exit
For CentOS 7,
reboot
ssh client again
echo $DISPLAY
centos72:10.0

Install Xming
Install Xming X11 display server (https://sourceforge.net/projects/xming/) on your desktop PC and launch it

Enable X11 forward for PuTTY
Connection > SSH > X11 > Enable X11 forwarding

Proxy

Add DNS Server
vi /etc/resolv.conf
nameserver 8.8.8.8
nameserver 4.4.4.4

Add Proxy Server
vi ~/.bash_profile
http_proxy=http://192.168.0.1:8080
export http_proxy
https_proxy=http://192.168.0.1:8080
export https_proxy

Setup Yum Proxy
vi /etc/yum.conf
proxy=http://192.168.0.1:8080

Install EPEL repository and xclip (for copying ssh keys using command only)
sudo yum -y install epel-release
sudo yum -y install xclip


Generate public key to remote machine
ssh-keygen -t rsa -C "admin@example.com"
cat ~/.ssh/id_rsa.pub
xclip -sel clip < ~/.ssh/id_rsa.pub
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.2

GUI

Install Desktop (Optional)

sudo yum -y groups install "GNOME Desktop"

Install XRDP
sudo yum install xrdp tigervnc-server
sudo chcon -t bin_t /usr/sbin/xrdp
sudo chcon -t bin_t /usr/sbin/xrdp-sesman
sudo systemctl enable xrdp.service

sudo systemctl start xrdp
sudo systemctl status xrdp
netstat -antup | grep xrdp
sudo vi /etc/xrdp/xrdp.ini
max_bpp=24

C++

glibc
sudo yum -y install glibc* cmake

C++ Development (for CentOS 7)
sudo yum -y group install "Development Tools"
whereis gcc
gcc --version

C++ Development (for CentOS 6)
echo Mandatory Packages:
sudo yum -y install autoconf automake binutils bison flex gcc gcc-c++ gettext libtool make patch pkgconfig redhat-rpm-config rpm-build rpm-sign
echo Default Packages:
sudo yum -y install byacc cscope ctags diffstat doxygen elfutils gcc-gfortran git indent intltool patchutils rcs subversion swig systemtap
echo Optional Packages:

sudo yum -y install cmake git libstdc++-docs
whereis gcc
gcc --version

GCC with Boost on CentOS (Optional)
http://joelinoff.com/blog/?p=1604#more-1604

Compile a Helloworld
rm -f foo.c && printf '#include<stdio.h>\n void main(void){ printf("Hello");}' >> foo.c && gcc foo.c -o foo && ./foo

JAVA

JVM

Installing Java 8 by RPM
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.rpm
sudo rpm -ivh jdk-8u111-linux-x64.rpm

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm

NETBEANS

Installing NetBeans JDK by SH
sudo yum -y install libXtst
wget http://download.netbeans.org/netbeans/8.1/final/bundles/netbeans-8.1-cpp-linux-x64.sh
chmod a+x netbeans-8.1-cpp-linux-x64.sh
./netbeans-8.1-cpp-linux-x64.sh


SO File Path (Required if want permanent environment variables)
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/NetBeansProjects/your/lib
export LD_LIBRARY_PATH

Uninstall Netbeans
/home/ricky/netbeans-8.1/uninstall.sh (no need sudo)

Eclipse
http://www.eclipse.org/downloads/eclipse-packages/?osType=linux&release=undefined

to be continued

SQLite

SQLite Development with C++
sudo yum install -y sqlite-devel


Python and RobotFramework

Python
sudo yum -y install python-devel python-setuptools

PIP
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py

RobotFramework
sudo pip --proxy http://10.23.31.130:8080 install paramiko robotframework robotframework-ride robotframework-sshlibrary 

wxPython
yum install wxPython python-paramiko sshpass



GCC Version
On CentOS 7.2
[ricky@pc009 ~]$ cat /etc/*release

CentOS Linux release 7.2.1511 (Core)
$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
On CentOS 7.3
[ricky@centos73 ~]$ cat /etc/*release
CentOS Linux release 7.3.1611 (Core)
[ricky@centos73 ~]$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

MiniConda



wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh

2016年3月24日 星期四

RobotFramework Installation Guide for Oracle Linux 7.1


RobotFramework Installation Guide for Oracle Linux 7.1

Check Host File
vi /etc/hosts
10.179.86.8     eras-st-robot  eras-st-robot.eth0

Set Host Name
hostnamectl set-hostname eras-st-robot02

Change SSHD config
vi /etc/ssh/sshd_config
  • X11Forwarding yes
  • X11UseLocalhost no
service sshd restart

Check $DISPLAY after reboot
echo $DISPLAY
10.179.86.8:10.0

Install Xming
Install Xming X11 display server (https://sourceforge.net/projects/xming/) on your desktop PC and launch it

Enable X11 forward for PuTTY
Connection > SSH > X11 > Enable X11 forwarding

Add DNS Server
vi /etc/resolv.conf
options rotate attempts:2 timeout:2
search assets.thomsonreuters.com
nameserver 10.238.127.253
nameserver 10.238.127.254

Add Proxy Server
vi ~/.bash_profile
http_proxy=http://10.23.31.130:8080
export http_proxy
https_proxy=http://10.23.31.130:8080
export https_proxy

Setup Yum Proxy
vi /etc/yum.conf
proxy=http://10.23.31.130:8080

Remove SPT Repo and Install the YCK repository
rm /etc/yum.repos.d/SPT.repo
scp ricky.leung@10.32.29.215:/data/tools/oel7.1_yum.repos.d/ol7-u1-x64-1_0-patch-current-YCK.repo /etc/yum.repos.d/ol7-u1-x64-1_0-patch-current-YCK.repo

NTP Service
yum install ntp
vi /etc/ntp.conf
server 10.32.29.101 iburst
systemctl restart ntpd
ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*10.32.29.101    .PPS.            1 u    2   64    1    1.259   -0.179   0.000


Python, Paramiko and RobotFramework
yum install python-devel python-setuptools glibc*
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
sudo pip --proxy http://10.23.31.130:8080 install paramiko robotframework robotframework-ride robotframework-sshlibrary

Install xauth and xclock
yum install xauth xclock

Install EPEL Repo and wxPython, paramiko and sshpass
rpm -ivh epel-release-7-5.noarch.rpm
yum install wxPython python-paramiko sshpass

Generate public key to TG and InputHandler
ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub reutadmin@10.179.86.7
ssh-copy-id -i ~/.ssh/id_rsa.pub 10.179.86.8

Run the test

Copy SystemTests possibly from GIT to to ~ and then use ride.py to open SystemTests/SystemTestInputHandler/SystemTestInputHandler.txt

2016年3月17日 星期四

robot framework 使用五:CentOS上运行robot framework 并自动发送测试结果

http://blog.csdn.net/mask5726/article/details/27520041

操作系统版本:centos 6.0  x86_64
想要在linux上运行robot framework的测试用例,需要安装以下工具和软件:
1.安装python 2.7.6 ,首先python --version 查看系统是否装有python,并且python的版本是不是我们要用的
Python 2.6.5
说明已经装有python 2.6.5,下载python2.7.6,下载地址:https://www.python.org/download#pubkeys  选择:Python 2.7.6 compressed source tarball (for Linux, Unix or Mac OS X) 
使用root用户登录,下载后的文件通过rz命令将文件Python-2.7.6.tgz上传到root用户目录下
 执行以下命令安装:
tar zxvf Python-2.7.6.tgz
3cd Python-2.7.6
4./configure --prefix=/usr/local
5make && make altinstall
安装完后执行:python2.7 --version
出现这个:Python 2.7.6
证明安装完成,安装的目录为:/usr/local/lib/python2.7
为便于和系统中的python2.6.5区分,运行python的时候用python2.7代替。
2.安装 robotframework-2.8.4.tar.gz ,下载地址:https://pypi.python.org/pypi/robotframework


通过rz命令上传到root用户根目录下,执行 tar -zxvf robotframework-2.8.4.tar.gz
cd robotframework-2.8.4
python setup.py install
安装完成后,运行pybot --version
出现:Robot Framework 2.8.4 (Python 2.7.6 on linux2)
表明安装成功。

3.安装selenium2library和其他需要的库
执行
easy_install-2.7 robotframework-selenium2library
easy_install-2.7 selenium
easy_install-2.7 decorator
然后验证
python2.7
Type "help", "copyright", "credits" or "license" for more information.
>>> import Selenium2Library
>>>
出现最后那个空行表明安装成功!
先安装ez_setup.py,下载地址:https://pypi.python.org/pypi/setuptools/#unix-wget
执行 python2.7 ez_setup.py
4.把我们的脚本目录test传到linux上,执行 pybot ./cases.txt 或者python -m robot.run ./test,即可运行。
5.linux上运行脚本,需要有display,解决办法是安装vnc或者xvbf,vns安装:
 yum -y groupinstall “X Window System” “Desktop” “Fonts” “General Purpose Desktop”

rpm -ivh /mnt/Server/vnc-server-4.1.2-9.el5.x86_64.rpm
service vncserver start
vncserver :1
启动vncserver之后会提示输入初始密码,输入并确认后就可以在windows机器上下载http://www.realvnc.com/download/登陆到这个Linux机器上用鼠标操作
我的机器vncserver装完后不能正常工作,所以采用第二种方式,安装 xvbf
yum -y install xorg-x11-server-Xvfb
yum -y install mesa-dri-drivers
dbus-uuidgen –ensure
执行:Xvbf后就可以成功运行脚本了,需要主要脚本的命名最好用英文。
下一篇再介绍如何自动执行测试用例和自动发送结果邮件吧。

2015年12月18日 星期五

C++ explicit call of operator new and delete



Below Code is equvalent:
  1.     {
  2.         A * a = new A;
  3.         delete a;
  4.     }
  5.     {
  6.         A * a = (A*)(::operator new(sizeof(A)));
  7.         a->A::A();
  8.         a->~A();
  9.         ::operator delete(a);
  10.     }

  1. #include <iostream>
  2. #include <list>
  3. #include <allocators>
  4. class A
  5. {
  6. public:
  7.     A(){std::cout << " A()\n";}
  8.     ~A(){std::cout << "~A()\n";}
  9. };
  10. int main()
  11. {
  12.     using namespace std;
  13.     {
  14.         A * a = new A;
  15.         delete a;
  16.     }
  17.     {
  18.         A * a = (A*)(::operator new(sizeof(A)));
  19.         a->A::A();
  20.         if (a!=0)
  21.         {
  22.             a->~A();
  23.             ::operator delete(a);
  24.         }
  25.     }
  26.     return 0;
  27. }

2007 to 2023 HP and Dell Servers Comparison

  HP Gen5 to Gen11  using ChatGPT HP ProLiant Gen Active Years CPU Socket Popular HP CPUs Cores Base Clock Max RAM Capacity Comparable Dell ...