Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
94b8167a
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
94b8167a
编写于
9月 18, 2018
作者:
B
Brian Johnson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactored arePortsAvailable to Utils and added support for passing in single port. GH #5674
上级
da473e0d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
30 deletion
+31
-30
tests/Cluster.py
tests/Cluster.py
+1
-30
tests/testUtils.py
tests/testUtils.py
+30
-0
未找到文件。
tests/Cluster.py
浏览文件 @
94b8167a
...
@@ -12,7 +12,6 @@ import datetime
...
@@ -12,7 +12,6 @@ import datetime
import
sys
import
sys
import
random
import
random
import
json
import
json
import
socket
import
errno
import
errno
from
core_symbol
import
CORE_SYMBOL
from
core_symbol
import
CORE_SYMBOL
...
@@ -131,7 +130,7 @@ class Cluster(object):
...
@@ -131,7 +130,7 @@ class Cluster(object):
producerFlag
=
"--producers %s"
%
(
totalProducers
)
producerFlag
=
"--producers %s"
%
(
totalProducers
)
tries
=
30
tries
=
30
while
not
Cluster
.
arePortsAvailable
(
set
(
range
(
self
.
port
,
self
.
port
+
totalNodes
+
1
))):
while
not
Utils
.
arePortsAvailable
(
set
(
range
(
self
.
port
,
self
.
port
+
totalNodes
+
1
))):
Utils
.
Print
(
"ERROR: Another process is listening on nodeos default port. wait..."
)
Utils
.
Print
(
"ERROR: Another process is listening on nodeos default port. wait..."
)
if
tries
==
0
:
if
tries
==
0
:
return
False
return
False
...
@@ -366,34 +365,6 @@ class Cluster(object):
...
@@ -366,34 +365,6 @@ class Cluster(object):
return
True
return
True
@
staticmethod
def
arePortsAvailable
(
ports
):
"""Check if specified ports are available for listening on."""
assert
(
ports
)
assert
(
isinstance
(
ports
,
set
))
for
port
in
ports
:
if
Utils
.
Debug
:
Utils
.
Print
(
"Checking if port %d is available."
%
(
port
))
assert
(
isinstance
(
port
,
int
))
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
try
:
s
.
bind
((
"127.0.0.1"
,
port
))
except
socket
.
error
as
e
:
if
e
.
errno
==
errno
.
EADDRINUSE
:
Utils
.
Print
(
"ERROR: Port %d is already in use"
%
(
port
))
else
:
# something else raised the socket.error exception
Utils
.
Print
(
"ERROR: Unknown exception while trying to listen on port %d"
%
(
port
))
Utils
.
Print
(
e
)
return
False
finally
:
s
.
close
()
return
True
# Initialize the default nodes (at present just the root node)
# Initialize the default nodes (at present just the root node)
def
initializeNodes
(
self
,
defproduceraPrvtKey
=
None
,
defproducerbPrvtKey
=
None
,
onlyBios
=
False
):
def
initializeNodes
(
self
,
defproduceraPrvtKey
=
None
,
defproducerbPrvtKey
=
None
,
onlyBios
=
False
):
port
=
Cluster
.
__BiosPort
if
onlyBios
else
self
.
port
port
=
Cluster
.
__BiosPort
if
onlyBios
else
self
.
port
...
...
tests/testUtils.py
浏览文件 @
94b8167a
...
@@ -6,6 +6,7 @@ from collections import namedtuple
...
@@ -6,6 +6,7 @@ from collections import namedtuple
import
inspect
import
inspect
import
json
import
json
import
shlex
import
shlex
import
socket
from
sys
import
stdout
from
sys
import
stdout
from
sys
import
exit
from
sys
import
exit
import
traceback
import
traceback
...
@@ -171,6 +172,35 @@ class Utils:
...
@@ -171,6 +172,35 @@ class Utils:
cmdArr
=
shlex
.
split
(
cmd
)
cmdArr
=
shlex
.
split
(
cmd
)
return
Utils
.
runCmdArrReturnJson
(
cmdArr
,
trace
=
trace
,
silentErrors
=
silentErrors
)
return
Utils
.
runCmdArrReturnJson
(
cmdArr
,
trace
=
trace
,
silentErrors
=
silentErrors
)
@
staticmethod
def
arePortsAvailable
(
ports
):
"""Check if specified port (as int) or ports (as set) is/are available for listening on."""
assert
(
ports
)
if
isinstance
(
ports
,
int
):
ports
=
{
ports
}
assert
(
isinstance
(
ports
,
set
))
for
port
in
ports
:
if
Utils
.
Debug
:
Utils
.
Print
(
"Checking if port %d is available."
%
(
port
))
assert
(
isinstance
(
port
,
int
))
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
try
:
s
.
bind
((
"127.0.0.1"
,
port
))
except
socket
.
error
as
e
:
if
e
.
errno
==
errno
.
EADDRINUSE
:
Utils
.
Print
(
"ERROR: Port %d is already in use"
%
(
port
))
else
:
# something else raised the socket.error exception
Utils
.
Print
(
"ERROR: Unknown exception while trying to listen on port %d"
%
(
port
))
Utils
.
Print
(
e
)
return
False
finally
:
s
.
close
()
return
True
###########################################################################################
###########################################################################################
class
Account
(
object
):
class
Account
(
object
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录